Error Handling

Guide to error handling patterns in the Deva SDK across components, authentication, and data fetching.


Overview

The SDK handles errors at multiple levels:

  1. Authentication Errors - OAuth flow failures, token issues

  2. Network Errors - API request failures, timeouts

  3. Streaming Errors - SSE connection issues, parsing errors

  4. Component Errors - Channel not found, post creation failures

  5. Validation Errors - Invalid input, missing required fields


Authentication Errors

OpenID Configuration Load Failure

Occurs when SDK cannot load OAuth configuration.

Causes:

  • Network connectivity issues

  • Invalid environment configuration

  • Server unavailable

Behavior:

Impact:

  • Provider initialization fails

  • Users cannot authenticate

  • App cannot use SDK features

Resolution:

  • Check network connectivity

  • Verify environment setting

  • Check Deva platform status


Authorization Code Exchange Failure

Occurs during OAuth callback when exchanging code for tokens.

Causes:

  • Invalid authorization code

  • Code already used

  • PKCE verification failure

  • Network timeout

Behavior:

Detection:

Resolution:

  • Retry login

  • Clear browser storage

  • Check redirect URI configuration


Token Refresh Failure

Occurs when automatic token refresh fails.

Causes:

  • Refresh token expired

  • Network error

  • Invalid refresh token

  • Server error

Behavior:

Impact:

  • User automatically logged out

  • Session cleared

  • Must re-authenticate

Prevention:

  • Don't manually clear sessionStorage

  • Maintain active browser session

  • Avoid long periods of inactivity


Network Errors

Data Fetching Errors

SWR automatically handles network errors with retries.

Error Exposure:

Retry Behavior:

  • Automatic retries with exponential backoff

  • Continues using stale data if available

  • Error state exposed via error property

Example:


API Request Failures

Manual API calls require explicit error handling.

Pattern:

Component Usage:


Streaming Errors

Stream Connection Failure

Occurs when SSE connection cannot be established.

Causes:

  • Network connectivity issues

  • Invalid message/thread ID

  • Authentication failure

  • Server error

Detection:

Error Component:

Behavior:


Stream Parsing Errors

Occurs when stream event data cannot be parsed.

Causes:

  • Malformed JSON

  • Unexpected event format

  • Encoding issues

Handling:

Recovery:

  • Error displayed to user

  • Stream aborted

  • User can retry by sending new message


Stream Interruption

Occurs when connection is lost during streaming.

Causes:

  • Network disconnection

  • Server timeout

  • Component unmount

  • User navigation

Cleanup:

Graceful Handling:


Component-Specific Errors

ChannelFeed Errors

Channel Not Found:

Post Creation Failure:


Intercom Errors

Deva Not Found:

Thread Creation Failure:

Message Send Failure:

  • Handled internally by Intercom

  • Error displayed to user

  • Allows retry


Error Boundaries

React Error Boundary Pattern

Recommended for production apps:


Best Practices

1. Always Handle Errors

Bad:

Good:


2. Provide User Feedback

Bad:

Good:


3. Implement Retry Logic


4. Log Errors Appropriately


5. Handle Edge Cases


Common Error Types

Authentication Errors

Error
Cause
Resolution

OpenID config load failure

Network/server issue

Check connectivity, retry

Code exchange failure

Invalid auth code

Retry login

Token refresh failure

Expired refresh token

Re-authenticate

Invalid credentials

Wrong client ID

Check configuration

Network Errors

Error
Cause
Resolution

401 Unauthorized

Invalid/expired token

Re-authenticate

403 Forbidden

Insufficient permissions

Check user access

404 Not Found

Resource doesn't exist

Verify ID/handle

500 Server Error

Server issue

Retry, contact support

Network timeout

Slow connection

Retry with backoff

Streaming Errors

Error
Cause
Resolution

Connection refused

Server unavailable

Retry later

Stream timeout

Long response time

Increase timeout

Parse error

Malformed data

Report to support

Connection dropped

Network interruption

Retry message


Error Response Format

API errors typically follow this format:


Last updated