Error Handling
The Smartbills SDK throws structured errors for every API failure. Each error class maps to a specific HTTP status code and includes contextual information to help you handle failures gracefully.Error hierarchy
All SDK errors extend a common base class:SmartbillsError (base)
Every error includes these properties:SmartbillsApiError
ExtendsSmartbillsError with response details:
Error types
SmartbillsValidationError (400)
Thrown when the request body fails server-side validation. Check theerrors array for field-level details.
SmartbillsAuthenticationError (401)
Thrown when the access token is missing, expired, or invalid.SmartbillsPermissionError (403)
Thrown when the authenticated user lacks permission for the requested action.SmartbillsNotFoundError (404)
Thrown when the requested resource does not exist.SmartbillsConflictError (409)
Thrown when the request conflicts with the current state of the resource (e.g., trying to approve an already-approved report).SmartbillsRateLimitError (429)
Thrown when the API rate limit is exceeded. Includes aretryAfter hint.
SmartbillsQuotaError (402/403)
Thrown when the business has exceeded its plan quota.SmartbillsNetworkError
Thrown when the request fails due to a network issue (DNS failure, connection reset, timeout).Type guards
The SDK exports type guard functions for each error class. These narrow theunknown error type in catch blocks:
Comprehensive error handler
Retryable errors
CheckisRetryable or use the isRetryableError guard to determine whether a request can be safely retried:
SmartbillsRateLimitError(429)SmartbillsNetworkError(connection failures)- Server errors (5xx) returned as
SmartbillsApiError
Request ID
Every error includes arequestId that you can provide to Smartbills support for debugging: