Skip to content

Commit bb6ffb9

Browse files
Merge branch 'master' of github.com:SyntaxArc/ArchiPy
2 parents a7453d6 + 0bc94f5 commit bb6ffb9

4 files changed

Lines changed: 283 additions & 272 deletions

File tree

archipy/helpers/utils/app_utils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,18 @@ def create_fastapi_app(
230230
config: BaseConfig | None = None,
231231
*,
232232
configure_exception_handlers: bool = True,
233+
include_common_responses: bool = True,
233234
lifespan: Callable[..., AbstractAsyncContextManager] | None = None,
234235
) -> FastAPI:
235-
"""Creates and configures a FastAPI application.
236+
"""Create and configure a FastAPI application.
236237
237238
Args:
238-
config (BaseConfig | None): Optional custom configuration. If not provided, uses global config.
239-
configure_exception_handlers (bool): Whether to configure exception handlers.
240-
lifespan: Callable[..., AbstractAsyncContextManager] | None = None,
239+
config (BaseConfig | None, optional): Custom configuration. If not provided, uses global config.
240+
configure_exception_handlers (bool, optional): Whether to configure exception handlers. Defaults to True.
241+
include_common_responses (bool, optional): Whether to configure common response definitions for all endpoints.
242+
Defaults to True.
243+
lifespan (Callable[..., AbstractAsyncContextManager] | None, optional): Custom lifespan context manager for the app.
244+
Defaults to None.
241245
242246
Returns:
243247
FastAPI: The configured FastAPI application instance.
@@ -255,7 +259,7 @@ def create_fastapi_app(
255259
swagger_ui_parameters=config.FASTAPI.SWAGGER_UI_PARAMS,
256260
docs_url=config.FASTAPI.DOCS_URL,
257261
redocs_url=config.FASTAPI.RE_DOCS_URL,
258-
responses=cast(dict[int | str, Any], common_responses),
262+
responses=cast(dict[int | str, Any], common_responses) if include_common_responses else None,
259263
lifespan=lifespan,
260264
)
261265

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 an operation fails due to insufficient account balance."""
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)