Skip to main content
Fli includes built-in error handling, automatic retries, and rate limiting to ensure reliable flight searches. This guide covers how to work with these features and implement additional error handling in your application.

Built-in error handling

Fli’s HTTP client includes automatic error handling with exponential backoff:

What’s handled automatically

The HTTP client (fli/search/client.py:37-39) automatically handles:
  • Rate limiting: 10 requests per second maximum
  • Automatic retries: Up to 3 attempts with exponential backoff
  • HTTP errors: Raises exceptions with descriptive messages
The rate limiter uses the @sleep_and_retry and @limits decorators to ensure you never exceed Google Flights’ rate limits.

Rate limiting

Fli enforces a rate limit of 10 requests per second to prevent overwhelming the Google Flights API:

How it works

The client implementation (fli/search/client.py:37-39):
  • @limits(calls=10, period=1) - Maximum 10 calls per second
  • @sleep_and_retry - Automatically waits when limit is reached
  • @retry - Retries failed requests with exponential backoff
Do not create multiple SearchFlights instances in rapid succession. Use a single instance or the shared client via get_client() to ensure rate limiting works correctly.

Retry logic

Built-in retries

Fli automatically retries failed requests up to 3 times with exponential backoff:
The exponential backoff means:
  • First retry: ~1 second delay
  • Second retry: ~2 seconds delay
  • Third retry: ~4 seconds delay

Custom retry logic

For more control, implement your own retry logic:

Advanced retry with Tenacity

For production applications, use the tenacity library for robust retry logic:

Validation errors

Fli uses Pydantic for data validation. Invalid inputs raise ValidationError:

Common validation errors

Parsing errors

When using the parsing utilities, catch ParseError exceptions:

Handling parse errors

API errors

Search operations can fail for various reasons:
The error messages from SearchFlights.search() include context about what failed, making debugging easier.

Best practices

1. Always use try-except blocks

2. Validate inputs before searching

3. Handle empty results gracefully

4. Use the shared client instance

5. Log errors for debugging

Debugging

When troubleshooting issues:
  1. Check validation errors - Ensure all required fields are provided and valid
  2. Verify date formats - Dates must be in YYYY-MM-DD format
  3. Confirm airport/airline codes - Use valid IATA codes from the enums
  4. Check rate limits - If seeing consistent failures, you may be hitting rate limits
  5. Review error messages - Fli provides descriptive error messages with context
If you encounter persistent API errors, ensure you’re not being blocked by Google Flights. The built-in rate limiting and browser impersonation help prevent this, but excessive requests can still trigger blocks.