2022-09-11 10:34:18 +00:00
|
|
|
from fastapi.exceptions import HTTPException
|
2022-09-13 05:31:15 +00:00
|
|
|
from starlette.requests import Request
|
|
|
|
from starlette.responses import JSONResponse
|
2022-09-11 10:34:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TokenAuthFailure(HTTPException):
|
2022-09-13 05:31:15 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class PermissionsError(HTTPException):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
async def http_exception(request: Request, exc: HTTPException):
|
|
|
|
return JSONResponse(
|
|
|
|
{"msg": exc.detail, "code": exc.status_code, "data": None},
|
|
|
|
status_code=exc.status_code,
|
|
|
|
headers=exc.headers,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
exception_handlers = {HTTPException: http_exception}
|