Error Handling

The SDK raises typed exception classes for different failure scenarios, making it simple to handle specific error conditions in your application.


Error Classes

All API errors inherit from the base FellohError class. You can catch the base class or target specific error types.

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 exception raised by the SDK includes structured data about the failure.

Attributes

  • Name
    message
    Type
    str
    Description

    A human-readable error message (also the string representation of the exception).

  • Name
    status_code
    Type
    int
    Description

    The HTTP status code. 0 for network-level failures.

  • Name
    errors
    Type
    list[dict]
    Description

    A list of structured error dicts returned by the API. Each includes title, message, code, type, and documentation_url.

  • Name
    meta
    Type
    dict
    Description

    Response metadata including request_id — useful for debugging with Felloh support.

Error Handling

from felloh import (
    FellohError,
    FellohNotFoundError,
    FellohValidationError,
)

try:
    await client.bookings.get("non-existent-id")
except FellohNotFoundError:
    print("Booking not found")
except FellohValidationError as e:
    # Inspect field-level validation errors
    for error in e.errors:
        print(f"{error['title']}: {error['message']}")
except FellohError as e:
    print(f"Status: {e.status_code}")
    print(f"Errors: {e.errors}")
    print(f"Request ID: {e.meta.get('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 max_retries attempts (default: 2).

You can configure this when creating the client:

Configuring Retries

from felloh import FellohClient
from felloh.types import FellohConfig

client = FellohClient(FellohConfig(
    public_key="your-public-key",
    private_key="your-private-key",
    max_retries=3,     # retry up to 3 times on 5xx/network errors
    timeout=15.0,      # 15 second timeout per request
))