new project

This commit is contained in:
long2ice
2021-04-25 17:17:21 +08:00
parent 28d66950fe
commit 7f957661ec
83 changed files with 2721 additions and 2752 deletions

View File

@ -1,7 +1,33 @@
from fastapi.exceptions import HTTPException
from starlette.requests import Request
from starlette.responses import JSONResponse
from fastapi import HTTPException
from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR
async def exception_handler(request: Request, exc: HTTPException):
return JSONResponse(status_code=exc.status_code, content={"msg": exc.detail},)
class ServerHTTPException(HTTPException):
def __init__(self, error: str = None):
super(ServerHTTPException, self).__init__(
status_code=HTTP_500_INTERNAL_SERVER_ERROR, detail=error
)
class InvalidResource(ServerHTTPException):
"""
raise when has invalid resource
"""
class NoSuchFieldFound(ServerHTTPException):
"""
raise when no such field for the given
"""
class FileMaxSizeLimit(ServerHTTPException):
"""
raise when the upload file exceeds the max size
"""
class FileExtNotAllowed(ServerHTTPException):
"""
raise when the upload file ext not allowed
"""