SocketTask.onError

Listen to WebSocket error events.

Prerequisites:

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

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 codes

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.

Sample code

copy
const socketTask = my.connectSocket({
  url: 'wss://...',  //  The url must start with ws:// or wss://
  multiple: true
});
socketTask.onError((res) => {
  console.log('socketTask.onError Failed to connect!',res);
});