Skip to content

Commit 12d2e4c

Browse files
authored
throwing errors instead of strings
1 parent 2286a0a commit 12d2e4c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/yawsSocketConnect.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
var getSocket = function (url, options) {
2525
if (!("Websocket" in window)) {
26-
throw "No Websocket Implementation found";
26+
throw new Error("No Websocket Implementation found");
2727
}
2828
/**
2929
* returns the value given or a default if that doesn't exist
@@ -43,7 +43,7 @@
4343
if (key in defaults) {
4444
return defaults[key];
4545
}
46-
throw "No default defined for " + key + ".";
46+
throw new Error("No default defined for " + key + ".");
4747
}
4848
if (parseInt(options[key], 10) !== options[key]) {
4949
return parseInt(options[key] * 1000, 10);
@@ -121,7 +121,7 @@
121121
*/
122122
return function (event) {
123123
if (typeof event.data !== "object") {
124-
throw "Got something (" + (typeof event.data) + ") that shouldn't be returned by the socket.";
124+
throw new Error("Got something (" + (typeof event.data) + ") that shouldn't be returned by the socket.");
125125
}
126126
if (event.data instanceof Blob) {
127127
event.target.onMessageHandler(event.data);
@@ -136,7 +136,7 @@
136136
reader.readAsArrayBuffer(event.data);
137137
return;
138138
}
139-
throw "Got an object of a type that shouldn't be returned by the socket.";
139+
throw new Error("Got an object of a type that shouldn't be returned by the socket.");
140140
};
141141
}
142142
/**
@@ -146,17 +146,17 @@
146146
*/
147147
return function (event) {
148148
if (typeof event.data !== "object") {
149-
throw "Got something (" + (typeof event.data) + ") that shouldn't be returned by the socket.";
149+
throw new Error("Got something (" + (typeof event.data) + ") that shouldn't be returned by the socket.");
150150
}
151151
if (event.data instanceof Blob) {
152152
event.target.onMessageHandler(event.data);
153153
return;
154154
}
155-
throw "Got an object of a type that shouldn't be returned by the socket.";
155+
throw new Error("Got an object of a type that shouldn't be returned by the socket.");
156156
};
157157
};
158158
if (typeof onMessage !== "function") {
159-
throw "The first parameter 'onMessage' is required to be a function accepting a single parameter of type Blob.";
159+
throw new Error("The first parameter 'onMessage' is required to be a function accepting a single parameter of type Blob.");
160160
}
161161
var Socket = getSocket(url, options);
162162
Socket.onMessageHandler = onMessage;

0 commit comments

Comments
 (0)