Download vetcopilot-backend/app/utils/exceptions.py from WWsCa/VetNet-LCPS: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/WWsCa/VetNet-LCPS/resolve/main/vetcopilot-backend/app/utils/exceptions.py
- Command line
-
hf download hf://WWsCa/VetNet-LCPS/vetcopilot-backend/app/utils/exceptions.py
-
curl -L -o exceptions.py https://huggingface.co/WWsCa/VetNet-LCPS/resolve/main/vetcopilot-backend/app/utils/exceptions.py
1.37 kB
| """ | |
| 自定义异常模块 | |
| 定义业务层异常,配合全局异常处理中间件使用。 | |
| """ | |
| class AppException(Exception): | |
| """应用基础异常""" | |
| def __init__(self, message: str = "服务器内部错误", code: int = 500): | |
| self.message = message | |
| self.code = code | |
| super().__init__(self.message) | |
| class NotFoundException(AppException): | |
| """资源未找到异常(404)""" | |
| def __init__(self, message: str = "请求的资源不存在"): | |
| super().__init__(message=message, code=404) | |
| class BadRequestException(AppException): | |
| """请求参数错误异常(400)""" | |
| def __init__(self, message: str = "请求参数有误"): | |
| super().__init__(message=message, code=400) | |
| class ConflictException(AppException): | |
| """资源冲突异常(409)""" | |
| def __init__(self, message: str = "资源状态冲突"): | |
| super().__init__(message=message, code=409) | |
| class ServiceUnavailableException(AppException): | |
| """服务不可用异常(503)""" | |
| def __init__(self, message: str = "服务暂不可用,请稍后重试"): | |
| super().__init__(message=message, code=503) | |
| class UnprocessableEntityException(AppException): | |
| """无法处理的实体异常(422)""" | |
| def __init__(self, message: str = "无法处理当前请求"): | |
| super().__init__(message=message, code=422) | |