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 descriptionresource: Resource type (Tweet, User)id: Resource ID
RateLimitError
message: Error descriptionrateLimit.limit: Rate limit caprateLimit.remaining: Remaining requestsrateLimit.reset: Reset timestamp
CrawlerError
message: Error descriptioncode: Error codedetails: Additional details
Best Practices
- Always wrap API calls in try-catch
- Handle specific error types
- Log errors for debugging
- Implement retry logic for transient errors
- Use webhooks for monitoring
Next Steps
- Webhook Notifications - Monitor errors
- API Reference - Method-specific errors