Spaces:
Running
Running
| from __future__ import annotations | |
| from typing import Any | |
| class OCRServiceError(Exception): | |
| """可预期、可返回给调用方的服务错误。""" | |
| def __init__( | |
| self, | |
| code: str, | |
| message: str, | |
| *, | |
| status_code: int = 400, | |
| details: dict[str, Any] | None = None, | |
| ) -> None: | |
| super().__init__(message) | |
| self.code = code | |
| self.message = message | |
| self.status_code = status_code | |
| self.details = details | |
| def as_dict(self) -> dict[str, Any]: | |
| error: dict[str, Any] = {"code": self.code, "message": self.message} | |
| if self.details is not None: | |
| error["details"] = self.details | |
| return error | |