Skip to content

Commit 9395c2c

Browse files
committed
Added InsufficientBalanceError
1 parent ec6695e commit 9395c2c

4 files changed

Lines changed: 275 additions & 268 deletions

File tree

archipy/helpers/utils/app_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def create_fastapi_app(
255255
swagger_ui_parameters=config.FASTAPI.SWAGGER_UI_PARAMS,
256256
docs_url=config.FASTAPI.DOCS_URL,
257257
redocs_url=config.FASTAPI.RE_DOCS_URL,
258-
responses=cast(dict[int | str, Any], common_responses),
258+
responses=cast(dict[int | str, Any], common_responses) if configure_exception_handlers else None,
259259
lifespan=lifespan,
260260
)
261261

archipy/models/errors/custom_errors.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,3 +640,20 @@ def __init__(
640640
error: The error detail or message.
641641
"""
642642
super().__init__(error, lang, additional_data={"requirements": requirements} if requirements else None)
643+
644+
645+
class InsufficientBalanceError(BaseError):
646+
"""Exception raised when a password does not meet the security requirements."""
647+
648+
def __init__(
649+
self,
650+
lang: LanguageType = LanguageType.FA,
651+
error: ErrorDetailDTO = ErrorMessageType.INSUFFICIENT_BALANCE.value,
652+
) -> None:
653+
"""Initializes the exception.
654+
655+
Args:
656+
lang: Language code for the error message (defaults to Persian).
657+
error: The error detail or message.
658+
"""
659+
super().__init__(error, lang)

archipy/models/types/error_message_types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ class ErrorMessageType(Enum):
196196
grpc_status=StatusCode.CANCELLED if GRPC_AVAILABLE else None,
197197
)
198198

199+
INSUFFICIENT_BALANCE = ErrorDetailDTO.create_error_detail(
200+
code="INSUFFICIENT_BALANCE",
201+
message_en="Insufficient balance for operation",
202+
message_fa="عدم موجودی کافی برای عملیات.",
203+
http_status=HTTPStatus.PAYMENT_REQUIRED if HTTP_AVAILABLE else None,
204+
grpc_status=StatusCode.FAILED_PRECONDITION if GRPC_AVAILABLE else None,
205+
)
206+
199207
# System Errors (500, 501, 503)
200208
INVALID_ENTITY_TYPE = ErrorDetailDTO.create_error_detail(
201209
code="INVALID_ENTITY",

0 commit comments

Comments
 (0)