catch and handle realtime errors?
Is there a way to catch and handle realtime connection errors? Right now it just write and error to the console log, No exceptions, event or error code returned.
e.g. call realitime connect with an empty room name.
3 Replies
Hi @DC. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To handle Realtime connection errors in Normcore, you can use the
connectionStateChanged
event provided by the Room class. This event allows you to monitor changes in the connection state, including error states. Here's how you can implement error handling:
1. First, subscribe to the connectionStateChanged
event on the Room object.
2. In the event handler, check for error states and handle them accordingly.
Here's an example of how you can implement this:
In this example, we're subscribing to the connectionStateChanged
event and checking for the Error
state. When an error occurs, you can handle it appropriately, such as logging the error, displaying a message to the user, or attempting to reconnect.
It's worth noting that while this method allows you to detect and respond to connection errors, it doesn't provide detailed error codes or exceptions. The error handling in Normcore is designed to be more event-driven rather than exception-based.
For more information on the Room class and its events, you can refer to the Room reference documentation.
Remember to unsubscribe from the event when your component is destroyed to prevent memory leaks:
This approach should allow you to catch and handle Realtime connection errors in a more controlled manner.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1259730396577529917> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
The only API we exposes is this room connection state which will tell you if there's an error but not which one. We've already started an API to provide proper error objects for all of the possible connection errors so you can branch on different error types or log them to analytics. I expect we'll ship that in the next month or two.