-
Notifications
You must be signed in to change notification settings - Fork 255
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
surface request error message, fixes #91 #107
Changes from 1 commit
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 |
---|---|---|
|
@@ -34,10 +34,10 @@ function EventSource (url, eventSourceInitDict) { | |
var self = this | ||
self.reconnectInterval = 1000 | ||
|
||
function onConnectionClosed () { | ||
function onConnectionClosed (message=undefined) { | ||
if (readyState === EventSource.CLOSED) return | ||
readyState = EventSource.CONNECTING | ||
_emit('error', new Event('error')) | ||
_emit('error', new Event('error', {message: message})) | ||
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. Use object destructure. 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. technically this makes it a breaking change as it breaks compatibility with node 0.12 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. Node.js 0.12 is by far obsolete and unsupported, so I would not worry about it. If it would be a still supported version, then I would agree it would be a breaking change and would accept not including it, but being not the case, it's better to keep up with latests language idioms to have a clean code. 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. I just point it out because it breaks your test suite 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. That's true. Can you be able to update the |
||
|
||
// The url may have been changed by a temporary | ||
// redirect. If that's the case, revert it now. | ||
|
@@ -121,7 +121,7 @@ function EventSource (url, eventSourceInitDict) { | |
req = (isSecure ? https : http).request(options, function (res) { | ||
// Handle HTTP errors | ||
if (res.statusCode === 500 || res.statusCode === 502 || res.statusCode === 503 || res.statusCode === 504) { | ||
_emit('error', new Event('error', {status: res.statusCode})) | ||
_emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage})) | ||
onConnectionClosed() | ||
return | ||
} | ||
|
@@ -130,7 +130,7 @@ function EventSource (url, eventSourceInitDict) { | |
if (res.statusCode === 301 || res.statusCode === 307) { | ||
if (!res.headers.location) { | ||
// Server sent redirect response without Location header. | ||
_emit('error', new Event('error', {status: res.statusCode})) | ||
_emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage})) | ||
return | ||
} | ||
if (res.statusCode === 307) reconnectUrl = url | ||
|
@@ -140,7 +140,7 @@ function EventSource (url, eventSourceInitDict) { | |
} | ||
|
||
if (res.statusCode !== 200) { | ||
_emit('error', new Event('error', {status: res.statusCode})) | ||
_emit('error', new Event('error', {status: res.statusCode, message: res.statusMessage})) | ||
return self.close() | ||
} | ||
|
||
|
@@ -210,7 +210,7 @@ function EventSource (url, eventSourceInitDict) { | |
}) | ||
}) | ||
|
||
req.on('error', onConnectionClosed) | ||
req.on('error', err => onConnectionClosed(err.message)) | ||
if (req.setNoDelay) req.setNoDelay(true) | ||
req.end() | ||
} | ||
|
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.
If you don't provide
message
argument, it's alreadyundefined
by default, so it's superfluous. Please remove the default value.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.
Whoops, TS linter artifact I forgot to cleanup, thanks!
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.
You are welcome :-)