-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Improve websocket error handling and fix #315 #320
Changes from all commits
fedbd52
3f31fc5
b09d15f
80b3431
392bbc9
e616cc2
1d90425
51bfe22
8ad9919
f0b53e2
69e4d36
0a6dc26
f125696
e01ff63
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 |
---|---|---|
|
@@ -8,11 +8,14 @@ class HMRServer { | |
}); | ||
|
||
this.wss.on('connection', ws => { | ||
ws.onerror = this.handleSocketError; | ||
if (this.unresolvedError) { | ||
ws.send(JSON.stringify(this.unresolvedError)); | ||
} | ||
}); | ||
|
||
this.wss.on('error', this.handleSocketError); | ||
|
||
return this.wss._server.address().port; | ||
} | ||
|
||
|
@@ -69,6 +72,15 @@ class HMRServer { | |
} | ||
} | ||
|
||
handleSocketError(err) { | ||
if (err.code === 'ECONNRESET') { | ||
// This gets triggered on page refresh, ignore this | ||
return; | ||
} | ||
// TODO: Use logger to print errors | ||
console.log(prettyError(err)); | ||
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. have you seen any other errors actually happen? should we just ignore them? 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. This was just for future error handling. 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. Other errors might be parser errors, like an invalid frame, an inflate error if you use permessage-deflate, a frame with a payload bigger than the |
||
} | ||
|
||
broadcast(msg) { | ||
const json = JSON.stringify(msg); | ||
for (let ws of this.wss.clients) { | ||
|
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 is probably not needed as it adds the listener after the server is bound. errors are forwarded from the internal
http.Server
and most of them (all?) are emitted when listening.