Skip to content

Throwing from onConnect - what's the proper pattern? #317

Answered by enisdenjo
theogravity asked this question in Q&A
Discussion options

You must be logged in to vote

Throwing from any of the server hooks close the WebSocket connection with a: 4500: Internal server error. The close reason indicates that the server occurred an unexpected error, is terminal by nature and should not happen. Important thing to note is that the client will report the 4500 close code immediately and not retry.

graphql-ws doesn't have opinions on how closing connections on errors should look like, so it just offers a basic solution in case of thrown errors in unexpected places. There are numerous close codes you can use on a WebSocket, they're all in your hands.

With this liberty, you can catch an error in a hook, close with whatever code is agreed with a client for that spec…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@theogravity
Comment options

Answer selected by theogravity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants