Error Handling

The SDK defines custom exceptions to handle various errors.

The Perseus Client SDK defines several custom exceptions to provide detailed error information.

PerseusException

class PerseusException(Exception):
    """Base exception for all Perseus client errors."""
    pass

This is the base exception for all errors originating from the Perseus client. All other custom exceptions inherit from this class.

APIException

class APIException(PerseusException):
    """Raised for errors returned by the Perseus API."""

    def __init__(self, status_code: int, message: str):
        self.status_code = status_code
        self.message = message
        super().__init__(f"API Error: {status_code}: {message}")

This exception is raised when the Perseus API returns an error. It includes the status_code from the API response and a message detailing the error.

Attributes:

  • status_code (int): The HTTP status code returned by the API.
  • message (str): A descriptive message from the API about the error.

ConfigurationException

class ConfigurationException(PerseusException):
    """Raised for configuration errors, such as a missing API token."""
    pass

This exception is raised when there are issues with the client's configuration, such as a missing or invalid API key, or incomplete database settings.

It is recommended to wrap your API calls in try...except blocks to gracefully handle these exceptions and provide meaningful feedback to your users.