-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sure that no string is emitted as an error #789
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -716,7 +716,7 @@ function initAsClient(address, protocols, options) { | |
var error; | ||
|
||
if (!self.emit('unexpected-response', req, res)) { | ||
error = new Error('unexpected server response (' + res.statusCode + ')'); | ||
error = new Error(`unexpected server response (${res.statusCode})`); | ||
req.abort(); | ||
self.emit('error', error); | ||
} | ||
|
@@ -735,7 +735,7 @@ function initAsClient(address, protocols, options) { | |
|
||
var serverKey = res.headers['sec-websocket-accept']; | ||
if (typeof serverKey === 'undefined' || serverKey !== expectedServerKey) { | ||
self.emit('error', 'invalid server key'); | ||
self.emit('error', new Error('invalid server key')); | ||
self.removeAllListeners(); | ||
socket.end(); | ||
return; | ||
|
@@ -754,7 +754,7 @@ function initAsClient(address, protocols, options) { | |
} | ||
|
||
if (protError) { | ||
self.emit('error', protError); | ||
self.emit('error', new Error(protError)); | ||
self.removeAllListeners(); | ||
socket.end(); | ||
return; | ||
|
@@ -767,7 +767,7 @@ function initAsClient(address, protocols, options) { | |
try { | ||
perMessageDeflate.accept(serverExtensions[PerMessageDeflate.extensionName]); | ||
} catch (err) { | ||
self.emit('error', 'invalid extension parameter'); | ||
self.emit('error', new Error('invalid extension parameter')); | ||
self.removeAllListeners(); | ||
socket.end(); | ||
return; | ||
|
@@ -870,10 +870,10 @@ function establishConnection(ReceiverClass, SenderClass, socket, upgradeHead) { | |
self.close(code, data); | ||
}; | ||
|
||
self._receiver.onerror = function onerror(reason, errorCode) { | ||
self._receiver.onerror = function onerror(error, errorCode) { | ||
// close the connection when the receiver reports a HyBi error code | ||
self.close(typeof errorCode !== 'undefined' ? errorCode : 1002, ''); | ||
self.emit('error', (reason instanceof Error) ? reason : (new Error(reason))); | ||
self.close(errorCode, ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.emit('error', error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}; | ||
|
||
// finalize the client | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,40 +46,6 @@ describe('WebSocket', function() { | |
ws.should.be.an.instanceOf(WebSocket); | ||
done(); | ||
}); | ||
|
||
it('should emit an error object when the receiver throws an error string', function(done) { | ||
|
||
var wss = new WebSocketServer({port: ++port}, function() { | ||
|
||
var ws = new WebSocket('ws://localhost:' + port); | ||
|
||
ws.on('open', function () { | ||
ws._receiver.error('This is an error string', 1002); | ||
}); | ||
|
||
ws.on('error', function (error) { | ||
error.should.be.an.instanceof(Error); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should emit an error object when the receiver throws an error object', function(done) { | ||
|
||
var wss = new WebSocketServer({port: ++port}, function() { | ||
|
||
var ws = new WebSocket('ws://localhost:' + port); | ||
|
||
ws.on('open', function () { | ||
ws._receiver.error(new Error('This is an error object'), 1002); | ||
}); | ||
|
||
ws.on('error', function (error) { | ||
error.should.be.an.instanceof(Error); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer needed tests. |
||
describe('options', function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added here 913afa3#diff-ee39beab4c8223a58e34e180ba59f345 but the issue it attempted to fix (#680) was actually caused by reentrance after cleanup.
This is no longer the case in master so it has been removed.