Overview
The Bread SDK provides a comprehensive error hierarchy for handling different failure scenarios. All errors inherit frombread.APIError.
Error Hierarchy
All Bread SDK errors inherit fromBreadError:
APIConnectionError - Network Issues
APIConnectionError - Network Issues
Connection failures, timeouts, network errors.Subclasses:
APITimeoutError- Request exceeded timeout threshold
APIStatusError - HTTP Status Errors
APIStatusError - HTTP Status Errors
HTTP error responses from the API (4xx, 5xx status codes).Subclasses:
BadRequestError(400) - Invalid request parametersAuthenticationError(401) - Invalid or missing API keyPermissionDeniedError(403) - Insufficient permissionsNotFoundError(404) - Resource doesn’t existConflictError(409) - Resource conflict (e.g., immutable field change)UnprocessableEntityError(422) - Validation errorRateLimitError(429) - Too many requestsInternalServerError(≥500) - Server-side error
APIResponseValidationError - Invalid Response
APIResponseValidationError - Invalid Response
API returned data that doesn’t match expected schema.Common causes: API version mismatch, malformed response
Error Status Codes
400 - BadRequestError
Malformed request
401 - AuthenticationError
Invalid API key
403 - PermissionDeniedError
Insufficient permissions
404 - NotFoundError
Resource not found
409 - ConflictError
Resource conflict (e.g., immutable field change)
422 - UnprocessableEntityError
Invalid entity
429 - RateLimitError
Rate limit exceeded
500+ - InternalServerError
Server error
Basic Error Handling
Specific Error Handling
Authentication Errors
Not Found Errors
Conflict Errors
Rate Limiting
Connection Errors
Error Properties
AllAPIError subclasses have:
message: Error messagerequest: Original request objectbody: Response body (if available)
APIStatusError additionally has:
response: Full response objectstatusCode: HTTP status code
Comprehensive Error Handler
Retry Configuration
The SDK automatically retries certain errors:- 408 Request Timeout
- 409 Conflict
- 429 Rate Limit
- ≥500 Internal Server Errors
- Connection errors
Timeout Configuration
Configure timeouts to prevent hanging:Async Error Handling
Error handling works the same with async client:Best Practices
Catch Specific Errors First
Catch Specific Errors First
Handle specific error types before catching generic
APIErrorImplement Retry Logic
Implement Retry Logic
Retry on transient errors (rate limits, timeouts, server errors)
Log Error Details
Log Error Details
Log status codes, request details, and error messages for debugging
Don't Retry Auth Errors
Don't Retry Auth Errors
Authentication and permission errors are not transient - fix the root cause
Use Circuit Breakers
Use Circuit Breakers
For production, implement circuit breakers to prevent cascading failures
Set Appropriate Timeouts
Set Appropriate Timeouts
Configure timeouts based on your use case (quick requests vs. long-running jobs)