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

Function http_error_handler

core/Exception.py:46–60  ·  view source on GitHub ↗

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

(_: Request, exc: HTTPException)

Source from the content-addressed store, hash-verified

44
45
46async 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
63class UnicornException(Exception):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected