Skip to content

Error Handling

SDK errors are delivered through 3 channels:

  1. init errorsinit() throws an Error
  2. Runtime errors — Delivered via onError callback
  3. Processing errors — Delivered as ERROR/REJECTED signals via onSignal (session maintained)

Error Codes

Error CodeCategoryDescription
SOCKET_FAILEDinitWebSocket connection failure or SDK key validation failure
STREAMING_FAILEDinitAgora streaming connection failure
SOCKET_DISCONNECTED_UNEXPECTEDLYRuntimeWebSocket abnormal termination
STREAMING_DISCONNECTED_UNEXPECTEDLYRuntimeAgora connection lost due to network issues, etc.
SERVER_ERRORRuntimeSERVER_ERROR signal received from server
WORKER_DISCONNECTEDRuntimeServer connection termination signal received

init Errors

init() throws an Error on failure. The SDK automatically cleans up and returns to IDLE state.

js
try {
  await SDK.init(options);
} catch (error) {
  console.error(error.message);
}
jsx
SDK.init({ sdk_key: 'YOUR_SDK_KEY', avatar_id: 'YOUR_AVATAR_ID' })
  .then(() => { initialized.current = true; })
  .catch((error) => console.error(error.message));

On init failure, onError is not called. Since init() throws an Error, handle it with try/catch.

messageCause
"Failed to connect: ..."SDK key validation or WebSocket connection failure
"Failed to connect streaming: ..."Streaming connection failure

Runtime Errors

Errors that occur during active connections after init. Delivered via the onError callback.

When a runtime error occurs, the SDK automatically cleans up connections and returns to IDLE state. The client can reconnect by calling init() after receiving onError + onStatus(IDLE).

Status Flow Per Error

Error CodeTriggerState Transition
(init throw)During initCONNECTING or SOCKET_CONNECTED -> IDLE
SOCKET_DISCONNECTED_UNEXPECTEDLYRuntimeCONNECTED_FINISH -> cleanup -> IDLE
STREAMING_DISCONNECTED_UNEXPECTEDLYRuntimeCONNECTED_FINISH -> cleanup -> IDLE
SERVER_ERRORRuntimeCONNECTED_FINISH -> cleanup -> IDLE
WORKER_DISCONNECTEDRuntimeCONNECTED_FINISH -> cleanup -> IDLE

Init errors are thrown by init(), while runtime errors are delivered via onError callback + onStatus(IDLE).

Error Handling Example

js
SDK.onError((error) => {
  console.error('SDK Error:', error.code, error.message);
});
Error CodemessageCause
SOCKET_DISCONNECTED_UNEXPECTEDLY"WebSocket disconnected unexpectedly: {code}"WebSocket abnormal termination
STREAMING_DISCONNECTED_UNEXPECTEDLY"Streaming disconnected: {reason}"Agora connection lost due to network issues, etc.
SERVER_ERRORServer message or "SERVER_ERROR"SERVER_ERROR signal received from server
WORKER_DISCONNECTEDServer message or "WORKER_DISCONNECTED"Server connection termination signal received

Processing Error Signals

ERROR and REJECTED signals do not terminate the session. They indicate failures for individual requests. Received via onSignal (not onError).

js
SDK.onSignal((data) => {
  if (data.signal === 'ERROR') {
    // Server processing error
    console.warn('Error:', data.payload?.type);
  }
  if (data.signal === 'REJECTED') {
    // Invalid input
    console.warn('Rejected:', data.payload?.type);
  }
});
Signalpayload.type examplesDescription
ERRORSTT_ERROR, LLM_ERROR, TTS_ERRORServer internal processing error
REJECTEDSTT_EMPTY, MODERATIONInput validation failure or policy violation