MCPcopy Create free account
hub / github.com/binkuolo/fastapi / http_error_handler

Function http_error_handler

core/Exception.py:76–90  ·  view source on GitHub ↗

http异常处理 :param _: :param exc: :return:

(_: Request, exc: HTTPException)

Source from the content-addressed store, hash-verified

74
75
76async 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
93class UnicornException(Exception):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected