refactor: 优化响应格式和错误处理 fix: 修复文件上传类型校验和删除无用PDF文件 perf: 添加估值评估审核时间字段和查询条件 docs: 更新Docker镜像版本至v1.8 test: 添加响应格式检查脚本 style: 统一API响应数据结构 chore: 清理无用静态文件和更新构建脚本
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from fastapi.exceptions import (
|
||
HTTPException,
|
||
RequestValidationError,
|
||
ResponseValidationError,
|
||
)
|
||
from fastapi.requests import Request
|
||
from fastapi.responses import JSONResponse
|
||
from tortoise.exceptions import DoesNotExist, IntegrityError
|
||
|
||
|
||
class SettingNotFound(Exception):
|
||
pass
|
||
|
||
|
||
async def DoesNotExistHandle(req: Request, exc: DoesNotExist) -> JSONResponse:
|
||
content = dict(
|
||
code=404,
|
||
msg=f"Object has not found, exc: {exc}, query_params: {req.query_params}",
|
||
data={},
|
||
)
|
||
return JSONResponse(content=content, status_code=404)
|
||
|
||
|
||
async def IntegrityHandle(_: Request, exc: IntegrityError) -> JSONResponse:
|
||
content = dict(
|
||
code=500,
|
||
msg=f"IntegrityError,{exc}",
|
||
data={},
|
||
)
|
||
return JSONResponse(content=content, status_code=500)
|
||
|
||
|
||
async def HttpExcHandle(_: Request, exc: HTTPException) -> JSONResponse:
|
||
content = dict(code=exc.status_code, msg=exc.detail, data={})
|
||
return JSONResponse(content=content, status_code=exc.status_code)
|
||
|
||
|
||
async def RequestValidationHandle(_: Request, exc: RequestValidationError) -> JSONResponse:
|
||
content = dict(code=422, msg=f"RequestValidationError, {exc}", data={})
|
||
return JSONResponse(content=content, status_code=422)
|
||
|
||
|
||
async def ResponseValidationHandle(_: Request, exc: ResponseValidationError) -> JSONResponse:
|
||
content = dict(code=500, msg=f"ResponseValidationError, {exc}", data={})
|
||
return JSONResponse(content=content, status_code=500)
|