fix: 修改错误处理的代码
This commit is contained in:
parent
edd672f8c2
commit
3dd46c1ccf
|
|
@ -8,24 +8,6 @@ from src.dtos import BaseResponse, ErrorModel
|
||||||
|
|
||||||
logger = logging.getLogger("uvicorn.error")
|
logger = logging.getLogger("uvicorn.error")
|
||||||
|
|
||||||
class HttpCodeMsg:
|
|
||||||
REGISTER_USER_ALREADY_EXISTS = "REGISTER_USER_ALREADY_EXISTS"
|
|
||||||
LOGIN_BAD_CREDENTIALS = "LOGIN_BAD_CREDENTIALS"
|
|
||||||
LOGIN_USER_NOT_VERIFIED = "LOGIN_USER_NOT_VERIFIED"
|
|
||||||
RESET_PASSWORD_BAD_TOKEN = "RESET_PASSWORD_BAD_TOKEN"
|
|
||||||
VERIFY_USER_BAD_TOKEN = "VERIFY_USER_BAD_TOKEN"
|
|
||||||
VERIFY_USER_ALREADY_VERIFIED = "VERIFY_USER_ALREADY_VERIFIED"
|
|
||||||
VERIFY_USER_TOKEN_EXPIRED = "VERIFY_USER_TOKEN_EXPIRED"
|
|
||||||
HTTP_200 = "OK"
|
|
||||||
HTTP_400 = "BAD_REQUEST"
|
|
||||||
HTTP_401 = "UNAUTHORIZED"
|
|
||||||
HTTP_403 = "FORBIDDEN"
|
|
||||||
HTTP_404 = "NOT_FOUND"
|
|
||||||
HTTP_405 = "METHOD_NOT_ALLOWED"
|
|
||||||
HTTP_500 = "INTERNAL_SERVER_ERROR"
|
|
||||||
HTTP_502 = "BAD_GATEWAY"
|
|
||||||
HTTP_503 = "SERVICE_UNAVAILABLE"
|
|
||||||
HTTP_504 = "GATEWAY_TIMEOUT"
|
|
||||||
|
|
||||||
def request_validation_error_handler(req: Request, exc: RequestValidationError):
|
def request_validation_error_handler(req: Request, exc: RequestValidationError):
|
||||||
"""
|
"""
|
||||||
|
|
@ -70,13 +52,6 @@ def http_exception_handler(req: Request, exc: HTTPException):
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
logger.error(f"{req.method} {req.url} , exception:{exc.detail}")
|
logger.error(f"{req.method} {req.url} , exception:{exc.detail}")
|
||||||
if exc.status_code == 400:
|
err = ErrorModel(code=exc.status_code, message=exc.detail)
|
||||||
err = ErrorModel(code=status.HTTP_400_BAD_REQUEST, message=exc.detail)
|
|
||||||
elif exc.status_code == 401:
|
|
||||||
err = ErrorModel(code=status.HTTP_401_UNAUTHORIZED, message=exc.detail)
|
|
||||||
elif exc.status_code == 500:
|
|
||||||
err = ErrorModel(code=status.HTTP_500_INTERNAL_SERVER_ERROR, message=exc.detail)
|
|
||||||
else:
|
|
||||||
err = None # 未定义的错误消息
|
|
||||||
res = BaseResponse(result=None, error=err)
|
res = BaseResponse(result=None, error=err)
|
||||||
return JSONResponse(status_code=exc.status_code, content=res.dict())
|
return JSONResponse(status_code=exc.status_code, content=res.dict())
|
||||||
Loading…
Reference in New Issue