Skip to main content
Version: 3.x

Taro.onSocketError(callback)

Listens on the WebSocket error event.

Reference

Type

(callback: (result: Callback) => void) => void

Parameters

Callback

The callback function for the WebSocket error event.

(result: CallbackResult) => void
PropertyType
resultCallbackResult

CallbackResult

PropertyTypeDescription
errMsgstringError message

Sample Code

Taro.connectSocket({
url: 'test.php'
})
Taro.onSocketOpen(function (res){
console.log('WebSocket connection is open!')
})
Taro.onSocketError(function (res){
console.log('WebSocket connection failed to open, please check!')
})

API Support

APIWeChat Mini-ProgramBaidu Smart-ProgramAlipay Mini-ProgramH5React Native
Taro.onSocketError✔️✔️✔️