ushka.http.exceptions
This module defines custom HTTP exception classes for the Ushka framework.
These exceptions correspond to specific HTTP status codes and are used to interrupt the normal request flow and return an appropriate error response to the client.
class HTTPError(Exception)
Base class for all HTTP-related exceptions in Ushka.
__init__(self, template: str = 'error.html', status_code: int = 400, message: str = 'Bad Request') -> None
Initializes the HTTPError.
Parameters
template | str | The template file to render for the error page. Defaults to "error.html". |
status_code | int | The HTTP status code. Defaults to 400. |
message | str | The error message. Defaults to "Bad Request". |
class HttpNotFound(HTTPError)
Exception raised for HTTP 404 Not Found errors.
__init__(self, template: str = 'error.html', status_code: int = 404, message: str = 'Not Found') -> None
Initializes the HttpNotFound error.
Parameters
template | str | The template file to render for the error page. Defaults to "error.html". |
status_code | int | The HTTP status code. Defaults to 404. |
message | str | The error message. Defaults to "Not Found". |
class HTTPBadRequest(HTTPError)
Exception raised for HTTP 400 Bad Request errors.
__init__(self, template: str = 'error.html', status_code: int = 400, message: str = 'Bad Request') -> None
Initializes the HTTPBadRequest error.
Parameters
template | str | The template file to render for the error page. Defaults to "error.html". |
status_code | int | The HTTP status code. Defaults to 400. |
message | str | The error message. Defaults to "Bad Request". |
class HTTPStaticServerNotFound(HttpNotFound)
Exception raised when a static file is not found or cannot be served.
This is a specialized version of HttpNotFound for issues related
to the static file server, such as file not found, path traversal
attempts, or file access errors.
__init__(self, template: str = 'error.html', status_code: int = 404, message: str = 'Static File Not Found') -> None
Initializes the HTTPStaticServerNotFound error.
Parameters
template | str | The template file to render for the error page. Defaults to "error.html". |
status_code | int | The HTTP status code. Defaults to 404. |
message | str | The error message. Defaults to "Static File Not Found". |
class HTTPPayloadTooLarge(HTTPError)
Exception raised for HTTP 413 Payload Too Large errors.
__init__(self, template: str = 'error.html', status_code: int = 413, message: str = 'Payload Too Large') -> None
Initializes the HTTPPayloadTooLarge error.
Parameters
template | str | The template file to render for the error page. Defaults to "error.html". |
status_code | int | The HTTP status code. Defaults to 413. |
message | str | The error message. Defaults to "Payload Too Large". |
class HTTPMethodNotAllowed(HTTPError)
Exception raised for HTTP 405 Method Not Allowed errors.
__init__(self, allowed: list[str] | None = None, template: str = 'error.html', status_code: int = 405, message: str = 'Method Not Allowed') -> None
Initializes the HTTPMethodNotAllowed error.
Parameters
allowed | list of str | Methods the path does accept; sent back in the |