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
Retry logic
Built-in retries
Fli automatically retries failed requests up to 3 times with exponential backoff:- 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 thetenacity library for robust retry logic:
Complete retry example
Complete retry example
Validation errors
Fli uses Pydantic for data validation. Invalid inputs raiseValidationError:
Common validation errors
Same departure and arrival airports
Same departure and arrival airports
Travel date in the past
Travel date in the past
Invalid time restrictions
Invalid time restrictions
Parsing errors
When using the parsing utilities, catchParseError 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:- Check validation errors - Ensure all required fields are provided and valid
- Verify date formats - Dates must be in
YYYY-MM-DDformat - Confirm airport/airline codes - Use valid IATA codes from the enums
- Check rate limits - If seeing consistent failures, you may be hitting rate limits
- Review error messages - Fli provides descriptive error messages with context