Overview
The Smartbills API uses conventional HTTP response codes to indicate the success or failure of an API request. Codes in the2xx range indicate success, 4xx indicate client errors, and 5xx indicate server errors.
HTTP Status Codes
Error Response Format
All errors follow a consistent JSON structure:Error Fields
Error Codes
Authentication Errors
Permission Errors
Validation Errors
Resource Errors
Rate Limit Errors
Server Errors
Handling Errors with the SDK
The Smartbills SDKs provide typed error classes for structured error handling:Validation Errors
Validation errors include detailed information about which fields failed:Handling Validation Errors
Retry Logic
Implement retry logic with exponential backoff for transient errors:Debugging with Request IDs
Every error response includes arequestId. Include this when contacting support:
- The
requestIdfrom the error response - The endpoint and HTTP method you called
- The timestamp of the error
- A description of what you expected to happen
Best Practices
Always Check Response Status
Always Check Response Status
Never assume a request succeeded. Always check the HTTP status code or catch exceptions from the SDK.
Use Type-Specific Error Handlers
Use Type-Specific Error Handlers
Handle different error types with appropriate actions: redirect to login for 401, show field errors for validation failures, retry for 429/5xx.
Log Errors with Context
Log Errors with Context
Log errors with sufficient context including the request ID, endpoint, and relevant parameters.
Display User-Friendly Messages
Display User-Friendly Messages
Do not show raw API error messages to end users. Map error codes to user-friendly messages in your application.
Implement Retry Logic
Implement Retry Logic
Implement exponential backoff for transient errors (429, 5xx). Do not retry client errors (4xx other than 429).
Related Resources
Rate Limits
Handle rate limiting
Authentication
Fix authentication errors
API Introduction
API overview
Webhooks
Set up webhooks