http异常处理 :param _: :param exc: :return:
(_: Request, exc: HTTPException)
| 74 | |
| 75 | |
| 76 | async def http_error_handler(_: Request, exc: HTTPException): |
| 77 | """ |
| 78 | http异常处理 |
| 79 | :param _: |
| 80 | :param exc: |
| 81 | :return: |
| 82 | """ |
| 83 | if exc.status_code == 401: |
| 84 | return JSONResponse({"detail": exc.detail}, status_code=exc.status_code) |
| 85 | |
| 86 | return JSONResponse({ |
| 87 | "code": exc.status_code, |
| 88 | "message": exc.detail, |
| 89 | "data": exc.detail |
| 90 | }, status_code=exc.status_code, headers=exc.headers) |
| 91 | |
| 92 | |
| 93 | class UnicornException(Exception): |
nothing calls this directly
no outgoing calls
no test coverage detected