Skip to main content

Error Handling Patterns

The Chat SDK provides typed error classes and patterns for handling failures in message handlers, API calls, and platform interactions.

Error Classes

The SDK exports specialized error types:

ChatError

Base error class for all SDK errors:
Example:

RateLimitError

Thrown when hitting platform rate limits:
Example:

LockError

Thrown when failing to acquire a thread lock:
Example:

NotImplementedError

Thrown when a feature is not supported by the platform:
Example:

Error Handling in Handlers

Try-Catch in Handlers

Wrap handler logic in try-catch:

Ephemeral Error Messages

Show errors only to the user who triggered them:

Validation Errors

Handle validation failures early:

Retry Logic

Implement exponential backoff for transient failures:
Return validation errors from modal submissions:

Graceful Degradation

Handle unsupported features gracefully:

Logging Errors

Use the built-in logger:

Complete Example

Robust error handling with retries and logging:

Best Practices

Unhandled errors in async handlers can crash your application. Wrap all handler logic in try-catch blocks.
Don’t clutter channels with error messages. Show validation and user-specific errors as ephemeral messages.
Include relevant context (threadId, userId, etc.) when logging errors to help with debugging.
Use exponential backoff when retrying rate-limited operations. Respect the retryAfterMs value.
Don’t expose stack traces or technical details to users. Translate errors into helpful messages.
Not all platforms support all features. Use feature detection and fallbacks.

Next Steps

Actions

Handle errors in button click handlers

Modals

Return validation errors from modal submissions