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:RateLimitError
Thrown when hitting platform rate limits:LockError
Thrown when failing to acquire a thread lock:NotImplementedError
Thrown when a feature is not supported by the platform: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:Modal Validation Errors
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
Always catch errors in handlers
Always catch errors in handlers
Unhandled errors in async handlers can crash your application. Wrap all handler logic in try-catch blocks.
Use ephemeral messages for user errors
Use ephemeral messages for user errors
Don’t clutter channels with error messages. Show validation and user-specific errors as ephemeral messages.
Log all errors with context
Log all errors with context
Include relevant context (threadId, userId, etc.) when logging errors to help with debugging.
Implement retry logic for rate limits
Implement retry logic for rate limits
Use exponential backoff when retrying rate-limited operations. Respect the retryAfterMs value.
Provide user-friendly error messages
Provide user-friendly error messages
Don’t expose stack traces or technical details to users. Translate errors into helpful messages.
Handle platform differences gracefully
Handle platform differences gracefully
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