onError( )


Adds an event handler that runs when an error occurs.

An error can occur when attempting to resubscribe after a disconnection. Errors that occur during the initial subscription process cause the Promise returned by the subscribe() function to reject and do not trigger onError() event handlers.

Method Declaration
Copy
function onError(handler: function): void;
Method Parameters
handlerfunctionRequired

handler(error: Error): void The name of the function or the function expression to run when an error occurs.

Add an error handler
JavaScript
import wixRealtimeFrontend from "wix-realtime-frontend"; // ... wixRealtimeFrontend.onError((error) => { let code = error.errorCode; let message = error.message; if (error.channel) { let channelName = error.channel.name; let resourceId = error.channel.resourceId; } });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?