first commit

This commit is contained in:
2024-11-07 17:44:29 +03:00
commit 643d6d8f65
247 changed files with 420800 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
from .api_exception_handlers.http_exception_handler import (
exception_handler_http,
exception_handler_exception,
)
__all__ = [
"exception_handler_http",
"exception_handler_exception",
]

View File

@@ -0,0 +1,27 @@
from json import loads
from fastapi import status
from fastapi.requests import Request
from fastapi.exceptions import HTTPException
from fastapi.responses import JSONResponse
def exception_handler_http(request: Request, exc: HTTPException):
print('headers', request.headers)
detail = loads(exc.detail)
return JSONResponse(
status_code=exc.status_code,
content={
"Data": detail.get('data', {}),
"Error": detail.get('error_case', 'UNKNOWN'),
"Message": detail.get('message', 'An error occurred while processing the request')
}
)
def exception_handler_exception(request: Request, exc: Exception):
print('headers', request.headers)
return JSONResponse(
status_code=status.HTTP_417_EXPECTATION_FAILED, content={"message": exc.__str__()}
)