D-ID Client SDK - v3.0.0-0
    Preparing search index...

    Class BaseError

    Base class of every error the SDK itself raises.

    Catching BaseError catches everything the SDK classified; branch on kind, which is stable, rather than on the message, which is not. Errors reach the application two ways, and each subclass says which applies: some are thrown to the caller of the method, so they reject the promise it returned; others are handed to onError because no call of yours was in flight when they happened. HttpError and NetworkError do both — the request that failed rejects, and the callback is notified as well.

    Not everything that reaches the application is one of these. The streaming transport is the main exception: a failure LiveKit raises inside a media call on an Expressive (V4) agent — no microphone publication to replace, a room that is not connected — rejects with a plain Error, and so do a few low-level guards inside connect(), such as a livekit-client package that is not installed, a transport the SDK does not recognize, or a stream the server created without a session id. An unknown auth type is a plain Error too. So keep the else throw error branch in a handler built on isDIDError.

    Subclasses: HttpError, NetworkError, WsError, StreamError, ValidationError, ChatCreationFailed and ChatModeDowngraded. When the caught value is typed unknown, isDIDError narrows it to DIDError, the union of those seven, so a switch on kind then narrows it to one class.

    Hierarchy (View Summary)

    Index
    • Creates an SDK error. The SDK builds these itself; applications normally only catch them.

      Parameters

      • message: string

        Human-readable description of the failure, used as the Error message.

      • kind: string = 'Error'

        Stable machine-readable code for the failure.

      • OptionaloriginalError: unknown

        The underlying error or value this one wraps, when there is one.

      Returns BaseError

    kind: string = 'Error'

    Stable machine-readable code for this failure, and the value to branch on.

    Every subclass redeclares it as the literal it always carries, so a switch on kind narrows a value isDIDError has recognized to that class: 'HttpError' on HttpError, 'NetworkError' on NetworkError, 'WSError' on WsError, 'StreamError' on StreamError, 'ValidationError' on ValidationError, 'ChatCreationFailed' on ChatCreationFailed and 'ChatModeDowngraded' on ChatModeDowngraded. It stays a plain string here on the base class: on a BaseError built directly it is whatever the caller passed, and 'Error' when nothing was. The Agents API's own classification of a failed request is HttpError.code, not this.

    originalError?: unknown

    The error or value that caused this one, when the SDK was wrapping something else.

    For a NetworkError this is the browser's own fetch rejection. It is not serialized as-is: toJson() takes only an Error cause's message.

    • Serializes the error into the JSON-safe ErrorJson payload for logging or reporting.

      The payload always carries kind and the message. The cause's message is added only when originalError is an Error and says something the message does not, truncated to 256 characters; any other cause is dropped. Subclasses extend the payload with the fields listed on their own pages.

      Returns ErrorJson

      The error as plain, JSON-serializable data.

      {
      "kind": "HttpError",
      "code": "InsufficientCreditsError",
      "message": "Account has insufficient credits",
      "httpStatus": 402,
      "endpoint": "/agt_x/chat/cht_y",
      "method": "POST"
      }
      {
      "kind": "NetworkError",
      "message": "Network request failed",
      "cause": "Failed to fetch",
      "endpoint": "/agt_x/chat/cht_y",
      "method": "POST",
      "durationMs": 12,
      "online": false,
      "visibility": "visible"
      }