Files
dify/api/libs/exception.py
T
33b1c57f9d feat: document API errors per code and narrow them with oRPC defined errors (#44001)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-10-14 08:25:50 +00:00

35 lines
1.1 KiB
Python

from collections.abc import Mapping
from typing import Any
from werkzeug.exceptions import HTTPException
class BaseHTTPException(HTTPException):
error_code: str = "unknown"
data: dict[str, Any] | None = None
def __init__(self, description=None, response=None):
super().__init__(description, response)
self.data = {
"code": self.error_code,
"message": self.description,
"status": self.code,
}
class RelayedHTTPError(BaseHTTPException):
"""An error whose ``code`` and status are relayed from a downstream service at runtime.
Emits the standard error body, but its codes cannot be listed per class. Declaring it
with ``error_responses`` keeps the operation's error codes and statuses open.
"""
def __init__(self, *, status: int, error_code: str, message: str, details: Mapping[str, Any] | None = None) -> None:
self.code = status
self.error_code = error_code
super().__init__(description=message)
if details:
assert self.data is not None
self.data["details"] = dict(details)