Exceptions¶
Exception classes for error handling.
Base Exception¶
Validation Exceptions¶
- class django_api_orm.exceptions.ValidationException[source]¶
Bases:
APIExceptionRaised when Pydantic validation fails.
Query Exceptions¶
- class django_api_orm.exceptions.DoesNotExist[source]¶
Bases:
APIExceptionRaised when a query returns no results (similar to Django’s DoesNotExist).
- class django_api_orm.exceptions.MultipleObjectsReturned[source]¶
Bases:
APIExceptionRaised when a query expected one result but returned multiple.
HTTP Exceptions¶
- class django_api_orm.exceptions.HTTPStatusError[source]¶
Bases:
APIExceptionRaised when an HTTP request returns an error status code.
This wraps httpx.HTTPStatusError to provide a consistent exception interface.
- class django_api_orm.exceptions.AuthenticationError[source]¶
Bases:
APIExceptionRaised when authentication fails (401 status).
- class django_api_orm.exceptions.RateLimitError[source]¶
Bases:
APIExceptionRaised when API rate limit is exceeded (429 status).
Connection Exceptions¶
- class django_api_orm.exceptions.ConnectionError[source]¶
Bases:
APIExceptionRaised when connection to the API fails.
- class django_api_orm.exceptions.TimeoutError[source]¶
Bases:
APIExceptionRaised when an API request times out.
Exception Hierarchy¶
APIException
├── ValidationException
├── DoesNotExist
├── MultipleObjectsReturned
├── ConnectionError
├── TimeoutError
├── AuthenticationError
├── RateLimitError
└── HTTPStatusError
Example Usage¶
Basic Exception Handling¶
from django_api_orm.exceptions import DoesNotExist, MultipleObjectsReturned
try:
user = User.objects.get(id=1)
except DoesNotExist:
print("User not found")
except MultipleObjectsReturned:
print("Multiple users found")
HTTP Error Handling¶
from django_api_orm.exceptions import (
AuthenticationError,
RateLimitError,
HTTPStatusError
)
try:
user = User.objects.get(id=1)
except AuthenticationError:
print("Please log in")
except RateLimitError:
print("Rate limit exceeded")
except HTTPStatusError as e:
print(f"HTTP error: {e}")
Connection Error Handling¶
from django_api_orm.exceptions import ConnectionError, TimeoutError
try:
user = User.objects.get(id=1)
except ConnectionError:
print("Failed to connect to API")
except TimeoutError:
print("Request timed out")
Generic Error Handling¶
from django_api_orm.exceptions import APIException
try:
user = User.objects.get(id=1)
except APIException as e:
print(f"API error: {e}")
See Also¶
Exceptions for detailed exception handling documentation