Error Handling

The SDK throws typed exception 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.

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

Properties

  • Name
    message
    Type
    string
    Description

    A human-readable error message (via getMessage()).

  • Name
    statusCode
    Type
    int
    Description

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

  • Name
    errors
    Type
    array
    Description

    An array of structured error arrays returned by the API. Each includes title, message, code, type, and documentation_url.

  • Name
    meta
    Type
    array
    Description

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

Error Handling

use Felloh\Exceptions\FellohError;
use Felloh\Exceptions\FellohNotFoundError;
use Felloh\Exceptions\FellohValidationError;

try {
    $client->bookings->get('non-existent-id');
} catch (FellohNotFoundError $e) {
    echo "Booking not found\n";
} catch (FellohValidationError $e) {
    // Inspect field-level validation errors
    foreach ($e->errors as $error) {
        echo "{$error['title']}: {$error['message']}\n";
    }
} catch (FellohError $e) {
    echo "Status: {$e->statusCode}\n";
    print_r($e->errors);
    echo "Request ID: {$e->meta['request_id']}\n";
}

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

use Felloh\FellohClient;
use Felloh\FellohConfig;

$client = new FellohClient(new FellohConfig(
    publicKey: 'your-public-key',
    privateKey: 'your-private-key',
    maxRetries: 3,     // retry up to 3 times on 5xx/network errors
    timeout: 15.0,     // 15 second timeout per request
));