Error Handling Mechanism

The H5Player utilizes a unified onError hook for error output. This hook allows access partners to capture and display errors as needed.

Syntax

  • player.hooks.onError.tap('an error occurred', callback[info, player?]);

Callback Format

Parameter Type Description
info: Object devId String Device number
code Number The detailed error code. If the code is SERVER_ERROR, this will be the s17 media service error code.
errorType String The type of error. Please refer to the following section for field descriptions.
subErrorType String The error details.
message String Error message
level Number It specifies whether the error is channel-specific or applies to the entire player. 1 for player-level errors, and 2 for channel-level errors. It is generally used for playback.
errorInfo object Custom parameter

Code Example

player = playerjs.createLivePlayer({ ...yourConfig });
interface ErrorInfo{
    info: {
        devId: String,
        code: Number,
        errorType: String,
        subErrorType: String,
        ...
    }
}
// For v2.x versions, use it as follows:
player.hooks.onError.tap('error', (errorInfo: ErrorInfo, player: playerInstance) => {
     const { errorType, subErrorType,description, info } = errorInfo;
     // If the business layer needs to provide an error prompt, for example, "Device offline".
     // If the project does not require internationalization, you can handle it as follows:
     console.error(errorType, ': ', description); // NETWORK_ERROR: Device offline.
     // If the project uses internationalization, such as i18n, you can handle it as follows:
     // Note: You need to add entries for errorType and subErrorType in the project first.
     const { NETWORK_ERROR, DEVICE_OFFLINE } = stPlayer.errorCode.sdkErrorCode;
     if (errorType == NETWORK_ERROR && subErrorType == DEVICE_OFFLINE) {
         // i18n needs to add entries.
         console.error(i18n('NETWORK_ERROR'), ': ', i18n('H5_SDK_DEVICE_OFFLINE'));
     }
     // If it's a channel-level error, you can handle it as follows:
     if (info.level === 2) {
         // If the error message requires Chinese prompts, you can replace subErrorType with description.
         console.error(`An error occurred on channel ${info.deviceInfos[0].channel}: `, subErrorType);
     }
});

Field Descriptions

  • errorType (Error Type))

There are 4 main categories:

Parameter Description
NETWORK_ERROR The network-related errors, including issues with s17 service responses.
MEDIA_ERROR The errors related to media playing, such as format issues or decoding problems.
OTHER_ERROR The errors that occur outside of the playing process, such as missing required fields.
PARAM_ERROR The parameter-related errors, including SDK and s17 parameter issues.
  • subErrorType (Sub Error Type)

It is more detailed than the previous category.

Error (SubErrorTypes) Description
OTHER_ERROR
H5_SDK_HTTPS_REQUIRED Website must use HTTPS protocol
H5_SDK_OPERATION_ERROR Operation error
H5_SDK_NO_MICROPHONE_PERMISSION No microphone permission
H5_SDK_WEBSOCKET_ERROR WebSocket error
NETWORK_ERROR
H5_SDK_INVALID_URL Invalid URL
H5_SDK_STREAM_ABORT Stream interruption
H5_SDK_SERVER_ERROR Server error (includes S17 interface errors except the following four)
H5_SDK_INVALID_DEVICE Invalid device
H5_SDK_DEVICE_IS_OCCUPIED Device occupied
H5_SDK_REQUEST_TIMEOUT Request timeout
H5_SDK_DEVICE_OFFLINE Device offline
H5_SDK_SEEK_FAILED Seek failed
H5_SDK_NETWORK_ERROR Network error
MEDIA_ERROR
H5_SDK_UNPACK_EXCEPTION Demuxing exception
H5_SDK_DECRYPTION AES decryption exception
H5_SDK_DECODING_EXCEPTION Decoding exception
H5_SDK_CURRENT_TIME_ERROR Current time error
H5_SDK_CACHE_MORE_THAN_2S Cache exceeds 2 seconds
PARAM_ERROR
H5_SDK_PARAM_SDK_ERROR SDK parameter error
H5_SDK_PARAM_S17_ERROR S17 parameter error
STREAM_TYPE_INVALID Invalid stream type
SERVER_ERROR
RESOURCE_NOT_AVAILABLE Resource unavailable
NO_GPU_RESOURCE Insufficient GPU server resources
VIDEO_OVER_LOAD GPU server overload