Error Handling
The SDK throws typed error classes for different failure scenarios, making it simple to handle specific error conditions in your application.
Error Classes
All API errors extend the base FellohError class. You can catch the base class or target specific error types using instanceof.
| Error Class | Status Code | Description |
|---|---|---|
FellohAuthenticationError | 401 | Invalid API credentials or expired token |
FellohForbiddenError | 403 | Insufficient permissions for the requested action |
FellohNotFoundError | 404 | The requested resource does not exist |
FellohValidationError | 422 | Request body failed validation — check errors for field-level details |
FellohRateLimitError | 429 | API rate limit exceeded |
FellohServerError | 5xx | Server error — the SDK automatically retries these |
FellohNetworkError | — | Network failure (timeout, DNS, connection refused) — also retried automatically |
The FellohError Object
Every error thrown by the SDK includes structured data about the failure.
Properties
- Name
message- Type
- string
- Description
A human-readable error message.
- Name
statusCode- Type
- integer
- Description
The HTTP status code.
0for network-level failures.
- Name
errors- Type
- array
- Description
An array of structured error objects returned by the API. Each includes
title,message,code,type, anddocumentation_url.
- Name
meta- Type
- object
- Description
Response metadata including
request_id— useful for debugging with Felloh support.
Error Properties
import {
FellohError,
FellohNotFoundError,
FellohValidationError,
} from '@felloh-org/node-sdk';
try {
await client.bookings.get('non-existent-id');
} catch (err) {
if (err instanceof FellohNotFoundError) {
console.log('Booking not found');
}
if (err instanceof FellohValidationError) {
// Inspect field-level validation errors
for (const error of err.errors) {
console.log(`${error.title}: ${error.message}`);
}
}
if (err instanceof FellohError) {
console.log(err.statusCode); // HTTP status code
console.log(err.errors); // API error details
console.log(err.meta); // Includes request_id
}
}
Automatic Retries
The SDK automatically retries requests that fail with a 5xx server error or a network error. Retries use exponential backoff
with a maximum of maxRetries attempts (default: 2).
You can configure this when creating the client:
Configuring Retries
const client = new FellohClient({
publicKey: 'your-public-key',
privateKey: 'your-private-key',
maxRetries: 3, // retry up to 3 times on 5xx/network errors
timeout: 15000, // 15 second timeout per request
});
