Error Handling
Complete guide for handling errors with FNE Client
Error Handling
This guide shows you how to handle errors with FNE Client efficiently.
Overview
FNE Client uses typed exceptions to handle errors. Each error type has its own exception, making handling and debugging easier.
Exception Hierarchy
Exception Types
ValidationException
Thrown when provided data is invalid:
AuthenticationException
Thrown when authentication fails (invalid API key):
BadRequestException
Thrown when the request is malformed (400):
NotFoundException
Thrown when the resource is not found (404):
ServerException
Thrown when the server encounters an error (500+):
MappingException
Thrown when data mapping fails:
Complete Error Handling
Complete Example
Error Format
All FNE exceptions implement a toArray() method to get a standardized format:
Localized Error Messages
Error messages are automatically localized according to configuration:
Error Logging
FNE Client automatically logs errors if a logger is configured:
Automatic Retry
For temporary server errors, you can implement a retry:
Best Practices
- Always handle exceptions: Never leave FNE exceptions unhandled
- Use specific types: Use specific exceptions rather than generic
FNEException - Log errors: Log errors for debugging
- User messages: Display user-friendly messages rather than technical messages
- Retry for server errors: Implement retry for temporary server errors
Next Steps
- Cache - Use cache to improve performance
- Logging - Configure logging for debugging
- Examples - Check out more error handling examples
