Skip to main content

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

Extends SmartbillsError with response details:

Error types

SmartbillsValidationError (400)

Thrown when the request body fails server-side validation. Check the errors 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 a retryAfter 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 the unknown error type in catch blocks:

Comprehensive error handler

Retryable errors

Check isRetryable or use the isRetryableError guard to determine whether a request can be safely retried:
The following errors are retryable by default:
  • SmartbillsRateLimitError (429)
  • SmartbillsNetworkError (connection failures)
  • Server errors (5xx) returned as SmartbillsApiError

Request ID

Every error includes a requestId that you can provide to Smartbills support for debugging: