-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add details to the "close" event
The close event will now include additional details to help debugging if anything has gone wrong. Example when a payload is over the maxHttpBufferSize value in HTTP long-polling mode: ```js socket.on("close", (reason, details) => { console.log(reason); // "transport error" // in that case, details is an error object console.log(details.message); "xhr post error" console.log(details.description); // 413 (the HTTP status of the response) // details.context refers to the XMLHttpRequest object console.log(details.context.status); // 413 console.log(details.context.responseText); // "" }); ``` Note: the error object was already included before this commit and is kept for backward compatibility Example when a payload is over the maxHttpBufferSize value with WebSockets: ```js socket.on("close", (reason, details) => { console.log(reason); // "transport close" // in that case, details is a plain object console.log(details.description); // "websocket connection closed" // details.context is a CloseEvent object console.log(details.context.code); // 1009 (which means "Message Too Big") console.log(details.context.reason); // "" }); ``` Example within a cluster without sticky sessions: ```js socket.on("close", (reason, details) => { console.log(details.context.status); // 400 console.log(details.context.responseText); // '{"code":1,"message":"Session ID unknown"}' }); ``` Note: we could also print some warnings in development for the "usual" errors: - CORS error - HTTP 400 with multiple nodes - HTTP 413 with maxHttpBufferSize but that would require an additional step when going to production (i.e. setting NODE_ENV variable to "production"). This is open to discussion! Related: - socketio/socket.io#3946 - socketio/socket.io#1979 - socketio/socket.io-client#1518
- Loading branch information
1 parent
6e1bbff
commit b9252e2
Showing
6 changed files
with
181 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.