16 lines
491 B
Python
16 lines
491 B
Python
from fastapi import HTTPException, Request
|
|
from app.common.reponse_code import response_error
|
|
|
|
from app import my_app
|
|
"""全局异常处理"""
|
|
|
|
|
|
@my_app.exception_handlers(HTTPException)
|
|
async def http_exception(request: Request, he: HTTPException):
|
|
return response_error(request.url + "出现异常:" + he.detail)
|
|
|
|
|
|
@my_app.exception_handlers(Exception)
|
|
async def http_exception(request: Request, he: Exception):
|
|
return response_error(request.url + "出现异常:" + he.detail)
|