fix(api): let a core failure name its own API error code

This commit is contained in:
imSp4rky
2026-11-25 15:43:14 -07:00
parent e4ba7c2908
commit fcda47d995
23 changed files with 453 additions and 151 deletions
+10 -1
View File
@@ -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.