trpc
trpc copied to clipboard
feat(client): wsClient onError
🎯 Changes
So far WebSocket connection errors where not being made known to a trpc client. While the wsClient keeps trying to reconnect in the background, there was no way for the application to be notified or make any decisions.
What was possible already:
- onError callback for subscriptions which react to TRPCErrors
- onClose callback for a wsClient if a once established connection dies
What is missing:
- a way to notice if not even an initial connection could be established
This PR introduces two features in two separate commits in case one is not accepted.
The first commit adds a onError
callback to createWSClient()
. This can be utilized to act upon a connection error, for example display a message to the user like "Did you forget to connect to the company VPN?"
The second commit builds upon the first and adds the ability to explicitly prevent further reconnection attempts if the application decides that the underlying issue is non-recoverable. Reconnection can still be triggered explicitly with wsClient.reconnect()
if the application decides that connection should now be possible again.
✅ Checklist
- [x] I have followed the steps listed in the Contributing guide.
- [x] If necessary, I have added documentation related to the changes made.
- [x] I have added or updated the tests related to the changes made.