event to functon handler completed

This commit is contained in:
2025-01-15 19:18:11 +03:00
parent 25539c56cc
commit 76d286b519
55 changed files with 1271 additions and 1092 deletions

View File

@@ -18,6 +18,7 @@ class HTTPExceptionApiHandler:
@staticmethod
def retrieve_error_status_code(exc: HTTPExceptionApi) -> int:
from ErrorHandlers import DEFAULT_ERROR
error_by_codes = BaseErrorModelClass.retrieve_error_by_codes()
grab_status_code = error_by_codes.get(
str(exc.error_code).upper(), DEFAULT_ERROR
@@ -27,12 +28,15 @@ class HTTPExceptionApiHandler:
@staticmethod
def retrieve_error_message(exc: HTTPExceptionApi, error_languages) -> str:
from ErrorHandlers import DEFAULT_ERROR
return error_languages.get(str(exc.error_code).upper(), DEFAULT_ERROR)
async def handle_exception(
self, request: Union[Request, WebSocket], exc: Exception
) -> Union[Response, Awaitable[None]]:
request_string = str(request.url) if isinstance(request, Request) else request.url.path
request_string = (
str(request.url) if isinstance(request, Request) else request.url.path
)
if isinstance(exc, HTTPExceptionApi):
error_languages = MergedErrorLanguageModels.get_language_models(
language=exc.lang
@@ -45,6 +49,7 @@ class HTTPExceptionApiHandler:
"message": error_message,
"lang": exc.lang,
"request": request_string,
"loc": exc.loc,
},
)
return self.RESPONSE_MODEL(
@@ -53,5 +58,6 @@ class HTTPExceptionApiHandler:
"message": "Internal Server Error",
"lang": "def",
"request": request_string,
"loc": exc.loc,
},
) # Handle other exceptions with a generic 500 error
) # Handle other exceptions with a generic 500 error

View File

@@ -1,5 +1,6 @@
class HTTPExceptionApi(Exception):
def __init__(self, error_code: str, lang: str):
def __init__(self, error_code: str, lang: str, loc: str = ""):
self.error_code = error_code
self.lang = lang
self.loc = loc

View File

@@ -4,10 +4,7 @@ from ErrorHandlers.ErrorHandlers.api_exc_handler import (
from ErrorHandlers.Exceptions.api_exc import (
HTTPExceptionApi,
)
DEFAULT_ERROR = "UNKNOWN_ERROR"
__all__ = [
"HTTPExceptionApiHandler",
"HTTPExceptionApi",
"DEFAULT_ERROR"
]
__all__ = ["HTTPExceptionApiHandler", "HTTPExceptionApi", "DEFAULT_ERROR"]

View File

@@ -11,4 +11,3 @@ class BaseError:
NOT_ACCEPTABLE: int = 406
INVALID_DATA: int = 422
UNKNOWN_ERROR: int = 502

View File

@@ -16,4 +16,3 @@ class BaseErrorModelClass:
}
language_model_status.update(clean_dict)
return language_model_status