Search.../

onError( )

Adds an event handler that runs when an error occurs.

Description

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.

Syntax

function onError(handler: ErrorHandler): void
handler: function ErrorHandler(error: Error): void

onError Parameters

NAME
TYPE
DESCRIPTION
handler

The name of the function or the function expression to run when an error occurs.

Returns

This function does not return anything.

Return Type:

void

ErrorHandler Parameters

NAME
TYPE
DESCRIPTION
error
Error

The error that occurred.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

Add an error handler

Copy Code
1import wixRealtimeFrontend from 'wix-realtime-frontend';
2
3// ...
4
5wixRealtimeFrontend.onError( (error) => {
6 let code = error.errorCode;
7 let message = error.message;
8 if(error.channel) {
9 let channelName = error.channel.name;
10 let resourceId = error.channel.resourceId;
11 }
12} );