my.onSocketError

Use this API to listen to WebSocket error events.

Prerequisites:

  • Supported SDK versions:
    • Android: 2.67.0
    • iOS: 2.80.0
  • Supported types of mini programs: DSL

Sample code

copy
// listen to WebSocket error event
my.onSocketError(function(res) {
  console.log('WebSocket error occurs');
  console.log('Error code:', res.error);
  console.log('Error message:', res.errorMessage);
});

Parameters

Function listener

The listener function to WebSocket error events. The function passes it in by wrapping the error message in the res object.

Object res

Property

Data type

Description

error

Number

The error code. 0 indicates success. For more information, see the following Error code section.

errorMessage

String

The error message.

Error code

Error code

Error message

Further action

6

Time out.

Check the network status and URL. Try again later.

8

Invalid Sec-WebSocket-Accept response.

Please negotiate with the server.

50

Network error.

Check the network status. Try again later.

65

Host unreachable.

Check whether the URL is correct.