Skip to content

Error Handling

Handle errors gracefully in your application.

Error Types

The SDK provides specific error types:

typescript
import { 
  NotFoundError, 
  RateLimitError, 
  CrawlerError,
  APIError 
} from '@blockchain-web-services/bws-x-sdk-node';

Handling Errors

typescript
try {
  const tweet = await client.getTweet('123');
} catch (error) {
  if (error instanceof NotFoundError) {
    console.log('Tweet not found');
  } else if (error instanceof RateLimitError) {
    console.log('Rate limited, retry after:', error.rateLimit.reset);
  } else if (error instanceof CrawlerError) {
    console.log('Scraping failed:', error.message);
  } else {
    console.error('Unknown error:', error);
  }
}

Error Properties

NotFoundError

  • message: Error description
  • resource: Resource type (Tweet, User)
  • id: Resource ID

RateLimitError

  • message: Error description
  • rateLimit.limit: Rate limit cap
  • rateLimit.remaining: Remaining requests
  • rateLimit.reset: Reset timestamp

CrawlerError

  • message: Error description
  • code: Error code
  • details: Additional details

Best Practices

  1. Always wrap API calls in try-catch
  2. Handle specific error types
  3. Log errors for debugging
  4. Implement retry logic for transient errors
  5. Use webhooks for monitoring

Next Steps

Released under the MIT License.