|
23 | 23 | */ |
24 | 24 | var getSocket = function (url, options) { |
25 | 25 | if (!("Websocket" in window)) { |
26 | | - throw "No Websocket Implementation found"; |
| 26 | + throw new Error("No Websocket Implementation found"); |
27 | 27 | } |
28 | 28 | /** |
29 | 29 | * returns the value given or a default if that doesn't exist |
|
43 | 43 | if (key in defaults) { |
44 | 44 | return defaults[key]; |
45 | 45 | } |
46 | | - throw "No default defined for " + key + "."; |
| 46 | + throw new Error("No default defined for " + key + "."); |
47 | 47 | } |
48 | 48 | if (parseInt(options[key], 10) !== options[key]) { |
49 | 49 | return parseInt(options[key] * 1000, 10); |
|
121 | 121 | */ |
122 | 122 | return function (event) { |
123 | 123 | 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."); |
125 | 125 | } |
126 | 126 | if (event.data instanceof Blob) { |
127 | 127 | event.target.onMessageHandler(event.data); |
|
136 | 136 | reader.readAsArrayBuffer(event.data); |
137 | 137 | return; |
138 | 138 | } |
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."); |
140 | 140 | }; |
141 | 141 | } |
142 | 142 | /** |
|
146 | 146 | */ |
147 | 147 | return function (event) { |
148 | 148 | 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."); |
150 | 150 | } |
151 | 151 | if (event.data instanceof Blob) { |
152 | 152 | event.target.onMessageHandler(event.data); |
153 | 153 | return; |
154 | 154 | } |
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."); |
156 | 156 | }; |
157 | 157 | }; |
158 | 158 | 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."); |
160 | 160 | } |
161 | 161 | var Socket = getSocket(url, options); |
162 | 162 | Socket.onMessageHandler = onMessage; |
|
0 commit comments