errors
errors
¶
Error classification and optional typed exceptions.
API calls never raise by default; they return an error dict. Responses now
also carry an error_kind key (alongside the legacy error_type) and, when
the API supplied one, reason. Use :func:raise_for_error to convert an
error dict into a typed exception.
CocApiError
¶
CocApiError(response: dict[str, Any])
Bases: Exception
Base class for typed API errors.
Source code in cocapi/errors.py
55 56 57 58 59 60 | |
classify_http_error
¶
classify_http_error(
status: int,
body: Any = None,
endpoint: str | None = None,
) -> tuple[str, str | None]
Return (error_kind, reason) for an HTTP error response.
Source code in cocapi/errors.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
raise_for_error
¶
raise_for_error(response: Any) -> Any
Raise a typed :class:CocApiError if response is an error dict.
Returns the response unchanged when it is not an error, so it can wrap calls::
clan = raise_for_error(api.clan_tag("#ABC"))
Source code in cocapi/errors.py
96 97 98 99 100 101 102 103 104 105 106 | |