Skip to content
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

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/eventsource.js
Expand Up @@ -34,10 +34,10 @@ function EventSource (url, eventSourceInitDict) {
var self = this
self.reconnectInterval = 1000

function onConnectionClosed () {
function onConnectionClosed (message=undefined) {
Copy link
Member

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 already undefined by default, so it's superfluous. Please remove the default value.

Copy link
Contributor Author

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!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are welcome :-)

if (readyState === EventSource.CLOSED) return
readyState = EventSource.CONNECTING
_emit('error', new Event('error'))
_emit('error', new Event('error', {message: message}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use object destructure.

Copy link

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just point it out because it breaks your test suite

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. Can you be able to update the .travis.yml file to remove the deprecated ones?


// The url may have been changed by a temporary
// redirect. If that's the case, revert it now.
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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()
}

Expand Down Expand Up @@ -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()
}
Expand Down