Files
mtusi2026lab2/src/errors.py
T

27 lines
673 B
Python

"""Errors that may safely be returned through the public API."""
from __future__ import annotations
from typing import Mapping
BASIC_CHALLENGE = 'Basic realm="messenger", charset="UTF-8"'
BEARER_CHALLENGE = 'Bearer realm="messenger"'
class ApiProblem(Exception):
"""An expected API failure with a stable status, machine code and headers."""
def __init__(
self,
status: int,
code: str,
message: str,
headers: Mapping[str, str] | None = None,
) -> None:
super().__init__(message)
self.status = status
self.code = code
self.message = message
self.headers = dict(headers or {})