"""Error helpers.""" from http import HTTPStatus class OwsError(Exception): """Exception which contains HTTP response data.""" def __init__( self, message: str, code: str = "bad_request", status: int = HTTPStatus.BAD_REQUEST, ): """Initialize exception.""" super().__init__(message, code, status) self.message = message self.code = code self.status = status def __str__(self): """Turn this exception into a string.""" return f"Status {self.status}: {self.message} ({self.code})" @classmethod def forbidden(cls, message: str, code: str = "forbidden"): """Return forbidden error.""" return OwsError(message, code, HTTPStatus.FORBIDDEN) @classmethod def not_found(cls, message: str, code: str = "not_found"): """Return not found error.""" return OwsError(message, code, HTTPStatus.NOT_FOUND)