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.
function onError(handler: function): void;
handler(error: Error): void
The name of the function or
the function expression to run when an error occurs.
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;
}
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.