http异常处理 :param _: :param exc: :return:
(_: Request, exc: HTTPException)
| 44 | |
| 45 | |
| 46 | async def http_error_handler(_: Request, exc: HTTPException): |
| 47 | """ |
| 48 | http异常处理 |
| 49 | :param _: |
| 50 | :param exc: |
| 51 | :return: |
| 52 | """ |
| 53 | if exc.status_code == 401: |
| 54 | return JSONResponse({"detail": exc.detail}, status_code=exc.status_code) |
| 55 | |
| 56 | return JSONResponse({ |
| 57 | "code": exc.status_code, |
| 58 | "message": exc.detail, |
| 59 | "data": exc.detail |
| 60 | }, status_code=exc.status_code, headers=exc.headers) |
| 61 | |
| 62 | |
| 63 | class UnicornException(Exception): |
nothing calls this directly
no outgoing calls
no test coverage detected