Skip to content

Exceptions

Exceptions

All API-related errors inherit from ApiError and typically include:

  • status_code: HTTP status code (if the error came from an HTTP response)
  • response_data: parsed JSON (or raw text) returned by the API

For example:

from hovercode import ApiError, HovercodeClient

client = HovercodeClient()

try:
    client.hovercodes.get_hovercode("not-a-real-id")
except ApiError as exc:
    print(exc.status_code)
    print(exc.response_data)

Error mapping

The SDK maps HTTP status codes to exception types:

  • 400 → ValidationError
  • 401 → AuthenticationError
  • 404 → NotFoundError
  • 429 → RateLimitError
  • 5xx → ServerError

Network/transport issues (DNS, timeouts, connection errors) raise NetworkError.

  • Catch specific errors when you want to branch logic (e.g., auth vs not found).
  • Catch ApiError for a broad “any Hovercode failure” handler.
from hovercode import AuthenticationError, HovercodeClient, NotFoundError

client = HovercodeClient()

try:
    client.hovercodes.get_hovercode("QR-CODE-ID")
except AuthenticationError:
    # Token missing/invalid
    raise
except NotFoundError:
    # Wrong QR code ID or it was deleted
    raise

Exceptions used by the Hovercode client library.

ApiError dataclass

Bases: Exception

Base exception for Hovercode API errors.

Attributes:

Name Type Description
message str

Human-readable error message.

status_code Optional[int]

HTTP status code, if the error originated from an HTTP response.

response_data Optional[object]

Parsed response payload (JSON-decoded object or text), when available.

__post_init__() -> None

Initialize the base Exception message.

AuthenticationError dataclass

Bases: ApiError

Raised when authentication fails (e.g., missing or invalid API token).

NetworkError dataclass

Bases: ApiError

Raised for network/transport errors (e.g., DNS issues, timeouts).

NotFoundError dataclass

Bases: ApiError

Raised when a requested resource is not found (HTTP 404).

RateLimitError dataclass

Bases: ApiError

Raised when the API rate limit is exceeded (HTTP 429).

ServerError dataclass

Bases: ApiError

Raised for server-side errors (HTTP 5xx).

ValidationError dataclass

Bases: ApiError

Raised when the API reports invalid input (HTTP 400).

WebhookSignatureError dataclass

Bases: ValidationError

Raised when a webhook signature fails verification.