Skip to content

Commit 759672d

Browse files
committed
Merge pull request #23 from tehdb/master
fix json parse and split not defined issues
2 parents ed56258 + a8c061c commit 759672d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/hub.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,18 @@
7979
// Ignore the ready message when viewing the hub directly
8080
if (message.data === 'cross-storage:ready') return;
8181

82-
request = JSON.parse(message.data);
82+
// Check whether message.data is a valid json
83+
try {
84+
request = JSON.parse(message.data);
85+
} catch (err) {
86+
return;
87+
}
88+
89+
// Check whether request.method is a string
90+
if (!request || typeof request.method !== 'string') {
91+
return;
92+
}
93+
8394
method = request.method.split('cross-storage:')[1];
8495

8596
if (!method) {

0 commit comments

Comments
 (0)