Skip to main content

Overview

Monzoh provides a comprehensive hierarchy of exception types to help you handle different error conditions that can occur when interacting with the Monzo API. All exceptions inherit from the base MonzoError class.

Exception Hierarchy

Base Exception

MonzoError

The base exception class that all other Monzoh exceptions inherit from.
Attributes:
  • message: Human-readable error message
  • response_data: Raw API response data (if available)
  • status_code: HTTP status code (if applicable)
Example:

Network and Connection Errors

MonzoNetworkError

Raised when network connectivity issues occur.
Common causes:
  • No internet connection
  • DNS resolution failures
  • Connection timeouts
  • SSL/TLS handshake failures
  • Proxy connection issues
Example:

Authentication Errors

MonzoAuthenticationError

Raised when authentication fails.
Common causes:
  • Expired access token with invalid refresh token
  • Revoked access token
  • Invalid OAuth2 credentials
  • Missing authentication headers
  • Insufficient permissions for the requested operation
Example:

Request Validation Errors

MonzoValidationError

Raised when request parameters fail validation.
Common causes:
  • Invalid parameter formats (e.g., malformed account IDs)
  • Missing required parameters
  • Parameter values out of allowed range
  • Invalid data types
  • Malformed request structure
Example:

HTTP Status Code Errors

MonzoBadRequestError

Raised for HTTP 400 Bad Request errors.
Common causes:
  • Malformed request data
  • Invalid parameter combinations
  • Business logic violations
  • Conflicting request parameters
  • Invalid request format
Example:

MonzoNotFoundError

Raised when requested resources don’t exist (HTTP 404).
Common causes:
  • Invalid or non-existent resource IDs
  • Resources that have been deleted
  • Attempting to access resources you don’t have permission for
  • Incorrect endpoint URLs
Example:

MonzoRateLimitError

Raised when API rate limits are exceeded (HTTP 429).
Common causes:
  • Making too many requests in a short time period
  • Exceeding daily/hourly request quotas
  • Multiple clients using the same credentials
  • Automated scripts making frequent requests
Example:

MonzoServerError

Raised for server-side errors (HTTP 5xx).
Common causes:
  • Temporary API server issues
  • Database connectivity problems on Monzo’s side
  • Internal server errors
  • Service maintenance or outages
Example:

Error Response Details

Many exceptions include additional details from the API response:

Best Practices for Error Handling

1. Specific Exception Handling

Handle specific exceptions rather than catching all errors:

2. Retry Logic with Different Strategies

3. Logging and Monitoring

4. Graceful Degradation

Testing Exception Handling

Proper exception handling is crucial for building robust applications with Monzoh. Always handle specific exception types and implement appropriate retry and fallback strategies based on the error type.