Files
ITWorx_MCP_Hub-Public/services/dataplane_router/errors.py
T

37 lines
1.4 KiB
Python

"""Stable, sanitized dataplane error categories."""
from __future__ import annotations
from dataclasses import dataclass
@dataclass(frozen=True)
class RouterError(Exception):
code: str
message: str
status_code: int
retryable: bool = False
AUTHENTICATION_REQUIRED = RouterError("AUTHENTICATION_REQUIRED", "Authentication is required.", 401)
TOKEN_INVALID = RouterError("TOKEN_INVALID", "The supplied credential is invalid.", 401)
ACCESS_DENIED = RouterError("ACCESS_DENIED", "Access to this endpoint is denied.", 403)
RESOURCE_NOT_REGISTERED = RouterError(
"RESOURCE_NOT_REGISTERED", "The requested endpoint is not registered.", 404
)
VALIDATION_FAILED = RouterError(
"VALIDATION_FAILED", "The request did not meet the protocol limits.", 400
)
TARGET_UNAVAILABLE = RouterError(
"TARGET_UNAVAILABLE", "The trusted gateway is unavailable.", 503, True
)
OVERLOADED = RouterError("OVERLOADED", "The gateway is at capacity; retry shortly.", 503, True)
TIMEOUT = RouterError("TIMEOUT", "The trusted gateway timed out.", 504, True)
RESULT_TOO_LARGE = RouterError(
"RESULT_TOO_LARGE", "The gateway response exceeded the output budget.", 502
)
UPSTREAM_PROTOCOL_ERROR = RouterError(
"UPSTREAM_PROTOCOL_ERROR", "The gateway returned an invalid protocol response.", 502
)
INTERNAL_ERROR = RouterError("INTERNAL_ERROR", "The dataplane router failed safely.", 500, True)