update events via wrapper routers
This commit is contained in:
@@ -10,6 +10,7 @@ from fastapi import Request, status
|
||||
from fastapi.responses import JSONResponse
|
||||
from pymongo.errors import PyMongoError, DuplicateKeyError, ConnectionFailure
|
||||
|
||||
from ApiLibrary.common.line_number import get_line_number_for_error
|
||||
from Services.MongoDb.Models.exceptions import (
|
||||
MongoBaseException,
|
||||
MongoConnectionError,
|
||||
@@ -54,6 +55,7 @@ def handle_mongo_errors(func: Callable) -> Callable:
|
||||
raise HTTPExceptionApi(
|
||||
lang="en",
|
||||
error_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
return wrapper
|
||||
|
||||
@@ -20,6 +20,7 @@ from pymongo.errors import (
|
||||
PyMongoError,
|
||||
)
|
||||
|
||||
from ApiLibrary.common.line_number import get_line_number_for_error
|
||||
from ErrorHandlers.ErrorHandlers.api_exc_handler import HTTPExceptionApi
|
||||
|
||||
|
||||
@@ -34,14 +35,28 @@ def handle_mongo_errors(func):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except ConnectionFailure:
|
||||
raise HTTPExceptionApi(error_code="HTTP_503_SERVICE_UNAVAILABLE", lang="en")
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_503_SERVICE_UNAVAILABLE",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
except ServerSelectionTimeoutError:
|
||||
raise HTTPExceptionApi(error_code="HTTP_504_GATEWAY_TIMEOUT", lang="en")
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_504_GATEWAY_TIMEOUT",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
except OperationFailure as e:
|
||||
raise HTTPExceptionApi(error_code="HTTP_400_BAD_REQUEST", lang="en")
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
except PyMongoError as e:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_500_INTERNAL_SERVER_ERROR", lang="en"
|
||||
error_code="HTTP_500_INTERNAL_SERVER_ERROR",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user