Skip to main content
When an SDK method fails, it throws IMessageError or one of its subclasses. First branch by error class with instanceof, then use error.code for the exact reason. Do not parse error.message for program logic. message is useful for logs and user-facing text. Use error.code, error.retryable, and error.context for decisions.

What You Can Do

Handle Errors

Check the most specific subclasses first, and handle IMessageError last. If the error is not from the SDK, rethrow it.

Error Object

All SDK errors include these fields:
Do not parse message. Server wording can change. Use error.code for stable decisions.

Common Error Codes

ErrorCode is both a runtime object and a TypeScript type. In most code, check the specific error class first, then compare error.code:
Common codes by category:
The server may return new error codes before your SDK version exports matching constants. Compare with ErrorCode constants when possible, and keep a fallback path for unknown error.code values.

gRPC Status Mapping

Most application code should not branch on grpcCode. Prefer error classes and error.code. Use this table when debugging transport-level behavior.

Retries

Set retry when creating the client. The SDK retries retryable unary requests automatically. Invalid input, missing resources, and permission failures do not become valid by retrying the same request.
RetryOptions:
Streaming requests are not retried automatically. When message, chat, group, or poll live streams disconnect, follow the concurrent recovery flow in events: consume live streams and im.events.catchUp(...) together. Location streams are different; location updates cannot be caught up.

Idempotency

Most calls do not need clientMessageId. Use it only when your queue or worker may rerun the same logical write after a crash or timeout. Automatic retry handles the same SDK call. clientMessageId handles your business job starting the same write again. Use the same clientMessageId every time you retry the same logical write:
Do not reuse one clientMessageId for different business operations. It represents one logical write, not a user ID, chat ID, or long-lived session ID.

Next Steps

  1. Events — recover after stream disconnects
  2. Messages — understand write methods, idempotency keys, and message errors
  3. Attachments — handle attachmentNotReady