Handling Errors

Any errors that occur during the WebSocket connection process or during communication with the server are emitted to the client through the error event. These errors may arise from authentication issues, connection failures, or server-side problems.

Error format

Each error object contains the following properties :

  • message : A human-readable string describing the error (e.g., "Unauthorized").

  • timestamp: The time when the error occurred, in ISO 8601 format (e.g., "2023-09-24T12:34:56.789Z").

Example error response

{
  "message": "Unauthorized",
  "timestamp": "2023-09-24T12:34:56.789Z"
}

Example Error Handling

You can handle these errors by listening for the error event as shown in the following example:

const socket = io('https://ws.one-record.fr/<namespace>', {
  auth: {
    access_token: 'wrong-token',
  },
});

socket.on('error', (error) => {
  console.error('Error received:', error);
});

Last updated