Error codes

Open in

AI Transport uses numeric error codes to identify specific failure conditions. Errors are surfaced as ErrorInfo objects, which include a code, statusCode, and message. Use the errorInfoIs utility to match errors by code.

Error code reference

General errors

CodeNameHTTP statusDescriptionRecovery
40000BadRequest400The request was malformed or missing required fields.Check the request payload and ensure all required fields are present.
40003InvalidArgument400An argument passed to a transport method was invalid.Verify the arguments match the expected types and constraints.

Transport errors

CodeNameHTTP statusDescriptionRecovery
104000EncoderRecoveryFailed500The encoder failed to recover after a publish error. The turn cannot continue.End the turn with reason 'error' and start a new one. The client will see the partial response up to the failure point.
104001TransportSubscriptionError500A channel subscription callback threw unexpectedly.Check the subscription callback for unhandled exceptions. Inspect the underlying error for details.
104002CancelListenerError500The transport failed to register or process a cancel listener.The turn may not respond to cancel signals. End the turn manually if needed.
104003TurnLifecycleError500A turn lifecycle event failed to publish.Check channel permissions and connection state. The turn-start or turn-end message could not be published.
104004TransportClosed400An operation was attempted on a transport that has been closed.Create a new transport instance. Do not reuse a closed transport.
104005TransportSendFailed500The client transport failed to send a message to the API endpoint.Check the API endpoint URL, network connectivity, and authentication. Inspect the underlying error for details.

errorInfoIs

Utility function to check if an ErrorInfo matches a specific error code.

JavaScript

1

2

3

import { errorInfoIs } from '@ably/ai-transport'

function errorInfoIs(errorInfo: Ably.ErrorInfo, error: ErrorCode): boolean
JavaScript

1

2

3

4

5

6

transport.on('error', (error) => {
  if (errorInfoIs(error, 104004)) {
    // Transport was closed, create a new one
    reconnect()
  }
})

Handle errors

Client-side

Subscribe to transport-level errors using on('error'):

JavaScript

1

2

3

4

5

const transport = createClientTransport({ channel, codec })

transport.on('error', (error) => {
  console.error(`Error ${error.code}: ${error.message}`)
})

Server-side

Handle errors at two levels: the transport level and the turn level.

JavaScript

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

// Transport-level errors
const transport = createServerTransport({
  channel,
  codec,
  onError(error) {
    console.error('Transport error:', error)
  },
})

// Turn-level errors
const turn = transport.newTurn({
  turnId,
  onError(error) {
    console.error('Turn error:', error)
  },
})

If a turn encounters an error during streaming, end the turn with reason 'error':

JavaScript

1

2

3

4

5

6

try {
  const { reason } = await turn.streamResponse(llmStream)
  await turn.end(reason)
} catch (error) {
  await turn.end('error')
}