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 ClassStatus CodeDescription
FellohAuthenticationError401Invalid API credentials or expired token
FellohForbiddenError403Insufficient permissions for the requested action
FellohNotFoundError404The requested resource does not exist
FellohValidationError422Request body failed validation — check errors for field-level details
FellohRateLimitError429API rate limit exceeded
FellohServerError5xxServer error — the SDK automatically retries these
FellohNetworkErrorNetwork 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. 0 for network-level failures.

  • Name
    errors
    Type
    array
    Description

    An array of structured error objects returned by the API. Each includes title, message, code, type, and documentation_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
});