mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-02 05:55:08 +00:00
fix(api): let a core failure name its own API error code
This commit is contained in:
@@ -9,7 +9,7 @@ older peer.
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum, StrEnum
|
||||
from typing import Any, NotRequired, Optional, TypedDict
|
||||
from typing import Any, NotRequired, Optional, TypedDict, TypeVar
|
||||
|
||||
HEALTH_ROUTE = "/api/health"
|
||||
SERVICES_ROUTE = "/api/services"
|
||||
@@ -74,6 +74,15 @@ class APIErrorCode(str, Enum):
|
||||
WORKER_ERROR = "WORKER_ERROR"
|
||||
|
||||
|
||||
E = TypeVar("E", bound=BaseException)
|
||||
|
||||
|
||||
def coded(exc: E, code: APIErrorCode) -> E:
|
||||
"""``exc`` with the API error code that ``categorize_exception`` reports for it, whatever its message says."""
|
||||
exc.error_code = code # type: ignore[attr-defined]
|
||||
return exc
|
||||
|
||||
|
||||
class ClientErrorKind(StrEnum):
|
||||
"""The error kinds a remote client gives a failure of its own. The server never sends them.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user