"""API error type."""
from __future__ import annotations
from collections.abc import Mapping
class ApiError(Exception):
"""Raised when the server returns a non-success status code."""
def __init__(
self,
status_code: int,
status: str,
body: bytes,
*,
headers: Mapping[str, str] | None = None,
response: object | None = None,
) -> None:
self.status_code: int = status_code
self.status: str = status
self.raw_body: bytes = body
self.body: bytes = body
self.headers: Mapping[str, str] | None = headers
self.response: object | None = response
super().__init__(f"{status_code} {status}")
@property
def text(self) -> str:
return self.raw_body.decode("utf-8", errors="replace")