birchrest.exceptions package

Submodules

birchrest.exceptions.api_error module

exception birchrest.exceptions.api_error.ApiError(user_message: str, status_code: int)[source]

Bases: Exception

A custom exception class used to represent API errors. Each error has a status code, a user-friendly message, and a base message (from the HTTP status code description). It can also convert itself into an HTTP response.

convert_to_response(res: Response) Response[source]

Convert the ApiError into an HTTP response object.

Args:

res (Response): The HTTP response object to send back to the client.

Returns:

Response: The HTTP response with the error details, status code, and correlation ID.

exception birchrest.exceptions.api_error.BadRequest(user_message: str = '')[source]

Bases: ApiError

Represents a 400 Bad Request error.

exception birchrest.exceptions.api_error.Conflict(user_message: str = '')[source]

Bases: ApiError

Represents a 409 Conflict error.

exception birchrest.exceptions.api_error.Forbidden(user_message: str = '')[source]

Bases: ApiError

Represents a 403 Forbidden error.

exception birchrest.exceptions.api_error.Gone(user_message: str = '')[source]

Bases: ApiError

Represents a 410 Gone error.

exception birchrest.exceptions.api_error.InternalServerError(user_message: str = '')[source]

Bases: ApiError

Represents a 500 Internal Server Error.

exception birchrest.exceptions.api_error.LengthRequired(user_message: str = '')[source]

Bases: ApiError

Represents a 411 Length Required error.

exception birchrest.exceptions.api_error.MethodNotAllowed(user_message: str = '')[source]

Bases: ApiError

Represents a 405 Method Not Allowed error.

exception birchrest.exceptions.api_error.NotFound(user_message: str = '')[source]

Bases: ApiError

Represents a 404 Not Found error.

exception birchrest.exceptions.api_error.PayloadTooLarge(user_message: str = '')[source]

Bases: ApiError

Represents a 413 Payload Too Large error.

exception birchrest.exceptions.api_error.PaymentRequired(user_message: str = '')[source]

Bases: ApiError

Represents a 402 Payment Required error.

exception birchrest.exceptions.api_error.PreconditionFailed(user_message: str = '')[source]

Bases: ApiError

Represents a 412 Precondition Failed error.

exception birchrest.exceptions.api_error.RequestTimeout(user_message: str = '')[source]

Bases: ApiError

Represents a 408 Request Timeout error.

exception birchrest.exceptions.api_error.ServiceUnavailable(user_message: str = '')[source]

Bases: ApiError

Represents a 503 Service Unavailable error.

exception birchrest.exceptions.api_error.TooManyRequests(user_message: str = '')[source]

Bases: ApiError

Represents a 429 Too Many Requests error.

exception birchrest.exceptions.api_error.Unauthorized(user_message: str = '')[source]

Bases: ApiError

Represents a 401 Unauthorized error.

exception birchrest.exceptions.api_error.UnprocessableEntity(user_message: str = '')[source]

Bases: ApiError

Represents a 422 Unprocessable Entity error.

exception birchrest.exceptions.api_error.UnsupportedMediaType(user_message: str = '')[source]

Bases: ApiError

Represents a 415 Unsupported Media Type error.

exception birchrest.exceptions.api_error.UpgradeRequired(user_message: str = '')[source]

Bases: ApiError

Represents a 426 Upgrade Required error.

birchrest.exceptions.invalid_controller_registration module

exception birchrest.exceptions.invalid_controller_registration.InvalidControllerRegistration(received_object: Any)[source]

Bases: Exception

Exception raised when an invalid class or instance is registered as a controller.

birchrest.exceptions.missing_auth_handler_error module

exception birchrest.exceptions.missing_auth_handler_error.MissingAuthHandlerError[source]

Bases: Exception

Exception raised when a protected route is used without an authentication handler.

Module contents

This module defines custom exceptions used throughout the BirchRest framework.

Exceptions: - InvalidControllerRegistration: Raised when a controller that does not inherit from the Controller base class is registered. - MissingAuthHandlerError: Raised when an authentication handler is required but has not been provided. - ApiError: Represents errors related to API requests, such as 404 Not Found or 500 Internal Server Error, with customizable status codes and messages.

These exceptions are used to manage error handling and enforce proper application behavior.

Exported exceptions: - InvalidControllerRegistration - MissingAuthHandlerError - ApiError

exception birchrest.exceptions.ApiError(user_message: str, status_code: int)[source]

Bases: Exception

A custom exception class used to represent API errors. Each error has a status code, a user-friendly message, and a base message (from the HTTP status code description). It can also convert itself into an HTTP response.

convert_to_response(res: Response) Response[source]

Convert the ApiError into an HTTP response object.

Args:

res (Response): The HTTP response object to send back to the client.

Returns:

Response: The HTTP response with the error details, status code, and correlation ID.

exception birchrest.exceptions.BadRequest(user_message: str = '')[source]

Bases: ApiError

Represents a 400 Bad Request error.

exception birchrest.exceptions.Conflict(user_message: str = '')[source]

Bases: ApiError

Represents a 409 Conflict error.

exception birchrest.exceptions.Forbidden(user_message: str = '')[source]

Bases: ApiError

Represents a 403 Forbidden error.

exception birchrest.exceptions.Gone(user_message: str = '')[source]

Bases: ApiError

Represents a 410 Gone error.

exception birchrest.exceptions.InternalServerError(user_message: str = '')[source]

Bases: ApiError

Represents a 500 Internal Server Error.

exception birchrest.exceptions.InvalidControllerRegistration(received_object: Any)[source]

Bases: Exception

Exception raised when an invalid class or instance is registered as a controller.

exception birchrest.exceptions.InvalidValidationModel(invalid_class: Type[Any])[source]

Bases: TypeError

Exception raised when the provided class is not a valid dataclass.

This error occurs when the user tries to use the validation decorators with a non-dataclass type. The error message will guide the user on how to resolve the issue by passing a proper dataclass to the validation decorators.

exception birchrest.exceptions.LengthRequired(user_message: str = '')[source]

Bases: ApiError

Represents a 411 Length Required error.

exception birchrest.exceptions.MethodNotAllowed(user_message: str = '')[source]

Bases: ApiError

Represents a 405 Method Not Allowed error.

exception birchrest.exceptions.MissingAuthHandlerError[source]

Bases: Exception

Exception raised when a protected route is used without an authentication handler.

exception birchrest.exceptions.NotFound(user_message: str = '')[source]

Bases: ApiError

Represents a 404 Not Found error.

exception birchrest.exceptions.PayloadTooLarge(user_message: str = '')[source]

Bases: ApiError

Represents a 413 Payload Too Large error.

exception birchrest.exceptions.PaymentRequired(user_message: str = '')[source]

Bases: ApiError

Represents a 402 Payment Required error.

exception birchrest.exceptions.RequestTimeout(user_message: str = '')[source]

Bases: ApiError

Represents a 408 Request Timeout error.

exception birchrest.exceptions.ServiceUnavailable(user_message: str = '')[source]

Bases: ApiError

Represents a 503 Service Unavailable error.

exception birchrest.exceptions.TooManyRequests(user_message: str = '')[source]

Bases: ApiError

Represents a 429 Too Many Requests error.

exception birchrest.exceptions.Unauthorized(user_message: str = '')[source]

Bases: ApiError

Represents a 401 Unauthorized error.

exception birchrest.exceptions.UnprocessableEntity(user_message: str = '')[source]

Bases: ApiError

Represents a 422 Unprocessable Entity error.

exception birchrest.exceptions.UnsupportedMediaType(user_message: str = '')[source]

Bases: ApiError

Represents a 415 Unsupported Media Type error.

exception birchrest.exceptions.UpgradeRequired(user_message: str = '')[source]

Bases: ApiError

Represents a 426 Upgrade Required error.