mirror of
https://github.com/langgenius/dify.git
synced 2026-10-16 15:35:32 +08:00
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
35 lines
1.1 KiB
Python
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)
|