Skip to content

Errors

The models/errors subpackage defines the custom exception hierarchy for ArchiPy. All errors subclass BaseError and are organized by domain: authentication, authorization, validation, resource management, networking, database, system, Keycloak, and Temporal.

Base Error

The root BaseError class that all ArchiPy exceptions inherit from, providing structured error codes and context.

Base error types for ArchiPy.

archipy.models.errors.base_error.BaseError

Bases: Exception

Base exception class for all custom errors.

This class provides a standardized way to handle errors with support for: - Localization of error messages - Additional context data - Integration with HTTP and gRPC status codes - Template string formatting for dynamic message formatting (using {variable} placeholders) - Text normalization and Persian number conversion

Subclasses should define the following class attributes

code (ClassVar[str]): Error code identifier message_en (ClassVar[str]): English error message (can use {variable} placeholders) message_fa (ClassVar[str]): Persian error message (can use {variable} placeholders) http_status (ClassVar[int]): HTTP status code grpc_status (ClassVar[int]): gRPC status code

Source code in archipy/models/errors/base_error.py
class BaseError(Exception):
    """Base exception class for all custom errors.

    This class provides a standardized way to handle errors with support for:
    - Localization of error messages
    - Additional context data
    - Integration with HTTP and gRPC status codes
    - Template string formatting for dynamic message formatting (using {variable} placeholders)
    - Text normalization and Persian number conversion

    Subclasses should define the following class attributes:
        code (ClassVar[str]): Error code identifier
        message_en (ClassVar[str]): English error message (can use {variable} placeholders)
        message_fa (ClassVar[str]): Persian error message (can use {variable} placeholders)
        http_status (ClassVar[int]): HTTP status code
        grpc_status (ClassVar[int]): gRPC status code

    """

    # Default error details - subclasses should override these
    code: ClassVar[str] = "UNKNOWN_ERROR"
    message_en: ClassVar[str] = "An unknown error occurred"
    message_fa: ClassVar[str] = "خطای ناشناخته‌ای رخ داده است."
    http_status: ClassVar[int] = 500
    grpc_status: ClassVar[int] = 13  # grpc.StatusCode.INTERNAL

    def __init__(
        self,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
        *args: object,
    ) -> None:
        """Initialize the error with message and optional context.

        Args:
            lang: Language code for the error message (defaults to Persian).
            additional_data: Additional context data for the error.
            *args: Additional arguments for the base Exception class.
        """
        if lang is None:
            self.lang = getattr(get_settings(), "LANGUAGE", LanguageType.FA)
        else:
            self.lang = lang

        self.additional_data = additional_data or {}

        # Initialize base Exception with the message
        super().__init__(self.get_message(), *args)

    def get_message(self) -> str:
        """Gets the localized error message based on the language setting.

        Returns:
            str: The error message in the current language.
        """
        return self.message_fa if self.lang == LanguageType.FA else self.message_en

    def to_dict(self) -> dict[str, Any]:
        """Converts the exception to a dictionary format for API responses.

        Returns:
            dict: A dictionary containing error details and additional data.
        """
        # Get the processed message (not the template)
        processed_message = self.get_message()

        response = {
            "error": self.code,
            "detail": {
                "code": self.code,
                "message": processed_message,
                "http_status": self.http_status,
                "grpc_status": self.grpc_status,
            },
        }

        # Add additional data if present
        if self.additional_data:
            detail = response["detail"]
            if isinstance(detail, dict):
                detail.update(self.additional_data)

        return response

    def __str__(self) -> str:
        """String representation of the exception.

        Returns:
            str: A formatted string containing the error code and message.
        """
        return (
            f"{self.__class__.__name__}("
            f"code='{self.code}', "
            f"message='{self.get_message()}', "
            f"http_status={self.http_status}, "
            f"grpc_status={self.grpc_status}, "
            f"additional_data={self.additional_data}"
            f")"
        )

    def __repr__(self) -> str:
        """Detailed string representation of the exception.

        Returns:
            str: A detailed string representation including all error details.
        """
        return (
            f"{self.__class__.__name__}("
            f"code='{self.code}', "
            f"message='{self.get_message()}', "
            f"http_status={self.http_status}, "
            f"grpc_status={self.grpc_status}, "
            f"additional_data={self.additional_data}"
            f")"
        )

    @property
    def message(self) -> str:
        """Gets the current language message.

        Returns:
            str: The error message in the current language.
        """
        return self.get_message()

archipy.models.errors.base_error.BaseError.code class-attribute

code: str = 'UNKNOWN_ERROR'

archipy.models.errors.base_error.BaseError.message_en class-attribute

message_en: str = 'An unknown error occurred'

archipy.models.errors.base_error.BaseError.message_fa class-attribute

message_fa: str = 'خطای ناشناخته\u200cای رخ داده است.'

archipy.models.errors.base_error.BaseError.http_status class-attribute

http_status: int = 500

archipy.models.errors.base_error.BaseError.grpc_status class-attribute

grpc_status: int = 13

archipy.models.errors.base_error.BaseError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.base_error.BaseError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.base_error.BaseError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.base_error.BaseError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.base_error.BaseError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

options: show_root_toc_entry: false heading_level: 3

Auth Errors

Exceptions for authentication and authorization failures.

Authentication and authorization error types.

archipy.models.errors.auth_errors.HTTP_AVAILABLE module-attribute

HTTP_AVAILABLE = True

archipy.models.errors.auth_errors.GRPC_AVAILABLE module-attribute

GRPC_AVAILABLE = True

archipy.models.errors.auth_errors.UnauthenticatedError

Bases: BaseError

Exception raised when a user is unauthenticated.

Source code in archipy/models/errors/auth_errors.py
class UnauthenticatedError(BaseError):
    """Exception raised when a user is unauthenticated."""

    code: ClassVar[str] = "UNAUTHENTICATED"
    message_en: ClassVar[str] = "You are not authorized to perform this action."
    message_fa: ClassVar[str] = "شما مجوز انجام این عمل را ندارید."
    http_status: ClassVar[int] = HTTPStatus.UNAUTHORIZED.value if HTTP_AVAILABLE and HTTPStatus is not None else 401
    grpc_status: ClassVar[int] = (
        StatusCode.UNAUTHENTICATED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAUTHENTICATED.value, tuple)
        else (
            StatusCode.UNAUTHENTICATED.value
            if GRPC_AVAILABLE and StatusCode is not None and StatusCode is not None
            else 16
        )
    )

archipy.models.errors.auth_errors.UnauthenticatedError.code class-attribute

code: str = 'UNAUTHENTICATED'

archipy.models.errors.auth_errors.UnauthenticatedError.message_en class-attribute

message_en: str = (
    "You are not authorized to perform this action."
)

archipy.models.errors.auth_errors.UnauthenticatedError.message_fa class-attribute

message_fa: str = 'شما مجوز انجام این عمل را ندارید.'

archipy.models.errors.auth_errors.UnauthenticatedError.http_status class-attribute

http_status: int = (
    HTTPStatus.UNAUTHORIZED.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 401
)

archipy.models.errors.auth_errors.UnauthenticatedError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAUTHENTICATED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAUTHENTICATED.value, tuple)
    else StatusCode.UNAUTHENTICATED.value
    if GRPC_AVAILABLE
    and StatusCode is not None
    and StatusCode is not None
    else 16
)

archipy.models.errors.auth_errors.UnauthenticatedError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.auth_errors.UnauthenticatedError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.auth_errors.UnauthenticatedError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.auth_errors.UnauthenticatedError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.auth_errors.UnauthenticatedError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.auth_errors.InvalidCredentialsError

Bases: BaseError

Exception raised for invalid credentials.

Source code in archipy/models/errors/auth_errors.py
class InvalidCredentialsError(BaseError):
    """Exception raised for invalid credentials."""

    code: ClassVar[str] = "INVALID_CREDENTIALS"
    message_en: ClassVar[str] = "Invalid username or password: {username}"
    message_fa: ClassVar[str] = "نام کاربری یا رمز عبور نامعتبر است: {username}"
    http_status: ClassVar[int] = HTTPStatus.UNAUTHORIZED.value if HTTP_AVAILABLE and HTTPStatus is not None else 401
    grpc_status: ClassVar[int] = (
        StatusCode.UNAUTHENTICATED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAUTHENTICATED.value, tuple)
        else (
            StatusCode.UNAUTHENTICATED.value
            if GRPC_AVAILABLE and StatusCode is not None and StatusCode is not None
            else 16
        )
    )

    def __init__(
        self,
        username: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidCredentialsError."""
        data = {"username": username} if username else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

    def get_message(self) -> str:
        """Gets the localized error message with username."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        username = self.additional_data.get("username", "username")
        return template.format(username=username)

archipy.models.errors.auth_errors.InvalidCredentialsError.code class-attribute

code: str = 'INVALID_CREDENTIALS'

archipy.models.errors.auth_errors.InvalidCredentialsError.message_en class-attribute

message_en: str = "Invalid username or password: {username}"

archipy.models.errors.auth_errors.InvalidCredentialsError.message_fa class-attribute

message_fa: str = (
    "نام کاربری یا رمز عبور نامعتبر است: {username}"
)

archipy.models.errors.auth_errors.InvalidCredentialsError.http_status class-attribute

http_status: int = (
    HTTPStatus.UNAUTHORIZED.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 401
)

archipy.models.errors.auth_errors.InvalidCredentialsError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAUTHENTICATED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAUTHENTICATED.value, tuple)
    else StatusCode.UNAUTHENTICATED.value
    if GRPC_AVAILABLE
    and StatusCode is not None
    and StatusCode is not None
    else 16
)

archipy.models.errors.auth_errors.InvalidCredentialsError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.auth_errors.InvalidCredentialsError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.auth_errors.InvalidCredentialsError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.auth_errors.InvalidCredentialsError.get_message

get_message() -> str

Gets the localized error message with username.

Source code in archipy/models/errors/auth_errors.py
def get_message(self) -> str:
    """Gets the localized error message with username."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    username = self.additional_data.get("username", "username")
    return template.format(username=username)

archipy.models.errors.auth_errors.InvalidCredentialsError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.auth_errors.TokenExpiredError

Bases: BaseError

Exception raised when a token has expired.

Source code in archipy/models/errors/auth_errors.py
class TokenExpiredError(BaseError):
    """Exception raised when a token has expired."""

    code: ClassVar[str] = "TOKEN_EXPIRED"
    message_en: ClassVar[str] = "Authentication token has expired"
    message_fa: ClassVar[str] = "توکن احراز هویت منقضی شده است."
    http_status: ClassVar[int] = HTTPStatus.UNAUTHORIZED.value if HTTP_AVAILABLE and HTTPStatus is not None else 401
    grpc_status: ClassVar[int] = (
        StatusCode.UNAUTHENTICATED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAUTHENTICATED.value, tuple)
        else (
            StatusCode.UNAUTHENTICATED.value
            if GRPC_AVAILABLE and StatusCode is not None and StatusCode is not None
            else 16
        )
    )

archipy.models.errors.auth_errors.TokenExpiredError.code class-attribute

code: str = 'TOKEN_EXPIRED'

archipy.models.errors.auth_errors.TokenExpiredError.message_en class-attribute

message_en: str = 'Authentication token has expired'

archipy.models.errors.auth_errors.TokenExpiredError.message_fa class-attribute

message_fa: str = 'توکن احراز هویت منقضی شده است.'

archipy.models.errors.auth_errors.TokenExpiredError.http_status class-attribute

http_status: int = (
    HTTPStatus.UNAUTHORIZED.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 401
)

archipy.models.errors.auth_errors.TokenExpiredError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAUTHENTICATED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAUTHENTICATED.value, tuple)
    else StatusCode.UNAUTHENTICATED.value
    if GRPC_AVAILABLE
    and StatusCode is not None
    and StatusCode is not None
    else 16
)

archipy.models.errors.auth_errors.TokenExpiredError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.auth_errors.TokenExpiredError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.auth_errors.TokenExpiredError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.auth_errors.TokenExpiredError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.auth_errors.TokenExpiredError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.auth_errors.InvalidTokenError

Bases: BaseError

Exception raised when a token is invalid.

Source code in archipy/models/errors/auth_errors.py
class InvalidTokenError(BaseError):
    """Exception raised when a token is invalid."""

    code: ClassVar[str] = "INVALID_TOKEN"
    message_en: ClassVar[str] = "Invalid authentication token"
    message_fa: ClassVar[str] = "توکن احراز هویت نامعتبر است."
    http_status: ClassVar[int] = HTTPStatus.UNAUTHORIZED.value if HTTP_AVAILABLE and HTTPStatus is not None else 401
    grpc_status: ClassVar[int] = (
        StatusCode.UNAUTHENTICATED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAUTHENTICATED.value, tuple)
        else (
            StatusCode.UNAUTHENTICATED.value
            if GRPC_AVAILABLE and StatusCode is not None and StatusCode is not None
            else 16
        )
    )

archipy.models.errors.auth_errors.InvalidTokenError.code class-attribute

code: str = 'INVALID_TOKEN'

archipy.models.errors.auth_errors.InvalidTokenError.message_en class-attribute

message_en: str = 'Invalid authentication token'

archipy.models.errors.auth_errors.InvalidTokenError.message_fa class-attribute

message_fa: str = 'توکن احراز هویت نامعتبر است.'

archipy.models.errors.auth_errors.InvalidTokenError.http_status class-attribute

http_status: int = (
    HTTPStatus.UNAUTHORIZED.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 401
)

archipy.models.errors.auth_errors.InvalidTokenError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAUTHENTICATED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAUTHENTICATED.value, tuple)
    else StatusCode.UNAUTHENTICATED.value
    if GRPC_AVAILABLE
    and StatusCode is not None
    and StatusCode is not None
    else 16
)

archipy.models.errors.auth_errors.InvalidTokenError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.auth_errors.InvalidTokenError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.auth_errors.InvalidTokenError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.auth_errors.InvalidTokenError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.auth_errors.InvalidTokenError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.auth_errors.SessionExpiredError

Bases: BaseError

Exception raised when a session has expired.

Source code in archipy/models/errors/auth_errors.py
class SessionExpiredError(BaseError):
    """Exception raised when a session has expired."""

    code: ClassVar[str] = "SESSION_EXPIRED"
    message_en: ClassVar[str] = "Session has expired: {session_id}"
    message_fa: ClassVar[str] = "نشست کاربری منقضی شده است: {session_id}"
    http_status: ClassVar[int] = HTTPStatus.UNAUTHORIZED.value if HTTP_AVAILABLE and HTTPStatus is not None else 401
    grpc_status: ClassVar[int] = (
        StatusCode.UNAUTHENTICATED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAUTHENTICATED.value, tuple)
        else (
            StatusCode.UNAUTHENTICATED.value
            if GRPC_AVAILABLE and StatusCode is not None and StatusCode is not None
            else 16
        )
    )

    def __init__(
        self,
        session_id: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize SessionExpiredError."""
        data = {"session_id": session_id} if session_id else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

    def get_message(self) -> str:
        """Gets the localized error message with session ID."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        session_id = self.additional_data.get("session_id", "session_id")
        return template.format(session_id=session_id)

archipy.models.errors.auth_errors.SessionExpiredError.code class-attribute

code: str = 'SESSION_EXPIRED'

archipy.models.errors.auth_errors.SessionExpiredError.message_en class-attribute

message_en: str = 'Session has expired: {session_id}'

archipy.models.errors.auth_errors.SessionExpiredError.message_fa class-attribute

message_fa: str = 'نشست کاربری منقضی شده است: {session_id}'

archipy.models.errors.auth_errors.SessionExpiredError.http_status class-attribute

http_status: int = (
    HTTPStatus.UNAUTHORIZED.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 401
)

archipy.models.errors.auth_errors.SessionExpiredError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAUTHENTICATED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAUTHENTICATED.value, tuple)
    else StatusCode.UNAUTHENTICATED.value
    if GRPC_AVAILABLE
    and StatusCode is not None
    and StatusCode is not None
    else 16
)

archipy.models.errors.auth_errors.SessionExpiredError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.auth_errors.SessionExpiredError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.auth_errors.SessionExpiredError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.auth_errors.SessionExpiredError.get_message

get_message() -> str

Gets the localized error message with session ID.

Source code in archipy/models/errors/auth_errors.py
def get_message(self) -> str:
    """Gets the localized error message with session ID."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    session_id = self.additional_data.get("session_id", "session_id")
    return template.format(session_id=session_id)

archipy.models.errors.auth_errors.SessionExpiredError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.auth_errors.PermissionDeniedError

Bases: BaseError

Exception raised when permission is denied.

Source code in archipy/models/errors/auth_errors.py
class PermissionDeniedError(BaseError):
    """Exception raised when permission is denied."""

    code: ClassVar[str] = "PERMISSION_DENIED"
    message_en: ClassVar[str] = "Permission denied for this operation"
    message_fa: ClassVar[str] = "دسترسی برای انجام این عملیات وجود ندارد."
    http_status: ClassVar[int] = (
        HTTPStatus.FORBIDDEN.value if HTTP_AVAILABLE and HTTPStatus is not None and HTTPStatus is not None else 403
    )
    grpc_status: ClassVar[int] = (
        StatusCode.PERMISSION_DENIED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.PERMISSION_DENIED.value, tuple)
        else (
            StatusCode.PERMISSION_DENIED.value
            if GRPC_AVAILABLE and StatusCode is not None and StatusCode is not None
            else 7
        )
    )

archipy.models.errors.auth_errors.PermissionDeniedError.code class-attribute

code: str = 'PERMISSION_DENIED'

archipy.models.errors.auth_errors.PermissionDeniedError.message_en class-attribute

message_en: str = 'Permission denied for this operation'

archipy.models.errors.auth_errors.PermissionDeniedError.message_fa class-attribute

message_fa: str = "دسترسی برای انجام این عملیات وجود ندارد."

archipy.models.errors.auth_errors.PermissionDeniedError.http_status class-attribute

http_status: int = (
    HTTPStatus.FORBIDDEN.value
    if HTTP_AVAILABLE
    and HTTPStatus is not None
    and HTTPStatus is not None
    else 403
)

archipy.models.errors.auth_errors.PermissionDeniedError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.PERMISSION_DENIED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.PERMISSION_DENIED.value, tuple
    )
    else StatusCode.PERMISSION_DENIED.value
    if GRPC_AVAILABLE
    and StatusCode is not None
    and StatusCode is not None
    else 7
)

archipy.models.errors.auth_errors.PermissionDeniedError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.auth_errors.PermissionDeniedError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.auth_errors.PermissionDeniedError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.auth_errors.PermissionDeniedError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.auth_errors.PermissionDeniedError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.auth_errors.AccountLockedError

Bases: BaseError

Exception raised when an account is locked.

Source code in archipy/models/errors/auth_errors.py
class AccountLockedError(BaseError):
    """Exception raised when an account is locked."""

    code: ClassVar[str] = "ACCOUNT_LOCKED"
    message_en: ClassVar[str] = "Account has been locked due to too many failed attempts"
    message_fa: ClassVar[str] = "حساب کاربری به دلیل تلاش‌های ناموفق متعدد قفل شده است"
    http_status: ClassVar[int] = (
        HTTPStatus.FORBIDDEN.value if HTTP_AVAILABLE and HTTPStatus is not None and HTTPStatus is not None else 403
    )
    grpc_status: ClassVar[int] = (
        StatusCode.PERMISSION_DENIED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.PERMISSION_DENIED.value, tuple)
        else (
            StatusCode.PERMISSION_DENIED.value
            if GRPC_AVAILABLE and StatusCode is not None and StatusCode is not None
            else 7
        )
    )

    def __init__(
        self,
        username: str | None = None,
        lockout_duration: int | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize AccountLockedError."""
        data = {}
        if username:
            data["username"] = username
        if lockout_duration:
            data["lockout_duration"] = lockout_duration
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.auth_errors.AccountLockedError.code class-attribute

code: str = 'ACCOUNT_LOCKED'

archipy.models.errors.auth_errors.AccountLockedError.message_en class-attribute

message_en: str = "Account has been locked due to too many failed attempts"

archipy.models.errors.auth_errors.AccountLockedError.message_fa class-attribute

message_fa: str = "حساب کاربری به دلیل تلاش\u200cهای ناموفق متعدد قفل شده است"

archipy.models.errors.auth_errors.AccountLockedError.http_status class-attribute

http_status: int = (
    HTTPStatus.FORBIDDEN.value
    if HTTP_AVAILABLE
    and HTTPStatus is not None
    and HTTPStatus is not None
    else 403
)

archipy.models.errors.auth_errors.AccountLockedError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.PERMISSION_DENIED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.PERMISSION_DENIED.value, tuple
    )
    else StatusCode.PERMISSION_DENIED.value
    if GRPC_AVAILABLE
    and StatusCode is not None
    and StatusCode is not None
    else 7
)

archipy.models.errors.auth_errors.AccountLockedError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.auth_errors.AccountLockedError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.auth_errors.AccountLockedError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.auth_errors.AccountLockedError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.auth_errors.AccountLockedError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.auth_errors.AccountDisabledError

Bases: BaseError

Exception raised when an account is disabled.

Source code in archipy/models/errors/auth_errors.py
class AccountDisabledError(BaseError):
    """Exception raised when an account is disabled."""

    code: ClassVar[str] = "ACCOUNT_DISABLED"
    message_en: ClassVar[str] = "Account has been disabled"
    message_fa: ClassVar[str] = "حساب کاربری غیرفعال شده است"
    http_status: ClassVar[int] = (
        HTTPStatus.FORBIDDEN.value if HTTP_AVAILABLE and HTTPStatus is not None and HTTPStatus is not None else 403
    )
    grpc_status: ClassVar[int] = (
        StatusCode.PERMISSION_DENIED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.PERMISSION_DENIED.value, tuple)
        else (
            StatusCode.PERMISSION_DENIED.value
            if GRPC_AVAILABLE and StatusCode is not None and StatusCode is not None
            else 7
        )
    )

    def __init__(
        self,
        username: str | None = None,
        reason: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize AccountDisabledError."""
        data = {}
        if username:
            data["username"] = username
        if reason:
            data["reason"] = reason
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.auth_errors.AccountDisabledError.code class-attribute

code: str = 'ACCOUNT_DISABLED'

archipy.models.errors.auth_errors.AccountDisabledError.message_en class-attribute

message_en: str = 'Account has been disabled'

archipy.models.errors.auth_errors.AccountDisabledError.message_fa class-attribute

message_fa: str = 'حساب کاربری غیرفعال شده است'

archipy.models.errors.auth_errors.AccountDisabledError.http_status class-attribute

http_status: int = (
    HTTPStatus.FORBIDDEN.value
    if HTTP_AVAILABLE
    and HTTPStatus is not None
    and HTTPStatus is not None
    else 403
)

archipy.models.errors.auth_errors.AccountDisabledError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.PERMISSION_DENIED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.PERMISSION_DENIED.value, tuple
    )
    else StatusCode.PERMISSION_DENIED.value
    if GRPC_AVAILABLE
    and StatusCode is not None
    and StatusCode is not None
    else 7
)

archipy.models.errors.auth_errors.AccountDisabledError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.auth_errors.AccountDisabledError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.auth_errors.AccountDisabledError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.auth_errors.AccountDisabledError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.auth_errors.AccountDisabledError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.auth_errors.InvalidVerificationCodeError

Bases: BaseError

Exception raised when a verification code is invalid.

Source code in archipy/models/errors/auth_errors.py
class InvalidVerificationCodeError(BaseError):
    """Exception raised when a verification code is invalid."""

    code: ClassVar[str] = "INVALID_VERIFICATION_CODE"
    message_en: ClassVar[str] = "Invalid verification code"
    message_fa: ClassVar[str] = "کد تایید نامعتبر است"
    http_status: ClassVar[int] = (
        HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None and HTTPStatus is not None else 400
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (
            StatusCode.INVALID_ARGUMENT.value
            if GRPC_AVAILABLE and StatusCode is not None and StatusCode is not None
            else 3
        )
    )

    def __init__(
        self,
        code: str | None = None,
        remaining_attempts: int | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidVerificationCodeError."""
        data = {}
        if code:
            data["code"] = code
        if remaining_attempts is not None:
            data["remaining_attempts"] = remaining_attempts
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.auth_errors.InvalidVerificationCodeError.code class-attribute

code: str = 'INVALID_VERIFICATION_CODE'

archipy.models.errors.auth_errors.InvalidVerificationCodeError.message_en class-attribute

message_en: str = 'Invalid verification code'

archipy.models.errors.auth_errors.InvalidVerificationCodeError.message_fa class-attribute

message_fa: str = 'کد تایید نامعتبر است'

archipy.models.errors.auth_errors.InvalidVerificationCodeError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE
    and HTTPStatus is not None
    and HTTPStatus is not None
    else 400
)

archipy.models.errors.auth_errors.InvalidVerificationCodeError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE
    and StatusCode is not None
    and StatusCode is not None
    else 3
)

archipy.models.errors.auth_errors.InvalidVerificationCodeError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.auth_errors.InvalidVerificationCodeError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.auth_errors.InvalidVerificationCodeError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.auth_errors.InvalidVerificationCodeError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.auth_errors.InvalidVerificationCodeError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

options: show_root_toc_entry: false heading_level: 3

Validation Errors

Exceptions for input validation and data integrity failures.

Validation error types.

archipy.models.errors.validation_errors.HTTP_AVAILABLE module-attribute

HTTP_AVAILABLE = True

archipy.models.errors.validation_errors.GRPC_AVAILABLE module-attribute

GRPC_AVAILABLE = True

archipy.models.errors.validation_errors.InvalidArgumentError

Bases: BaseError

Exception raised for invalid arguments.

Source code in archipy/models/errors/validation_errors.py
class InvalidArgumentError(BaseError):
    """Exception raised for invalid arguments."""

    code: ClassVar[str] = "INVALID_ARGUMENT"
    message_en: ClassVar[str] = "Invalid argument provided: {argument}"
    message_fa: ClassVar[str] = "پارامتر ورودی نامعتبر است: {argument}"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        argument_name: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidArgumentError."""
        data = {"argument": argument_name} if argument_name else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

    def get_message(self) -> str:
        """Gets the localized error message with argument name."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        argument = self.additional_data.get("argument", "argument")
        return template.format(argument=argument)

archipy.models.errors.validation_errors.InvalidArgumentError.code class-attribute

code: str = 'INVALID_ARGUMENT'

archipy.models.errors.validation_errors.InvalidArgumentError.message_en class-attribute

message_en: str = 'Invalid argument provided: {argument}'

archipy.models.errors.validation_errors.InvalidArgumentError.message_fa class-attribute

message_fa: str = 'پارامتر ورودی نامعتبر است: {argument}'

archipy.models.errors.validation_errors.InvalidArgumentError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidArgumentError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidArgumentError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidArgumentError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidArgumentError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidArgumentError.get_message

get_message() -> str

Gets the localized error message with argument name.

Source code in archipy/models/errors/validation_errors.py
def get_message(self) -> str:
    """Gets the localized error message with argument name."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    argument = self.additional_data.get("argument", "argument")
    return template.format(argument=argument)

archipy.models.errors.validation_errors.InvalidArgumentError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidFormatError

Bases: BaseError

Exception raised for invalid data formats.

Source code in archipy/models/errors/validation_errors.py
class InvalidFormatError(BaseError):
    """Exception raised for invalid data formats."""

    code: ClassVar[str] = "INVALID_FORMAT"
    message_en: ClassVar[str] = "Invalid data format"
    message_fa: ClassVar[str] = "فرمت داده نامعتبر است"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        format_type: str | None = None,
        expected_format: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidFormatError."""
        data = {}
        if format_type:
            data["format_type"] = format_type
        if expected_format:
            data["expected_format"] = expected_format
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.validation_errors.InvalidFormatError.code class-attribute

code: str = 'INVALID_FORMAT'

archipy.models.errors.validation_errors.InvalidFormatError.message_en class-attribute

message_en: str = 'Invalid data format'

archipy.models.errors.validation_errors.InvalidFormatError.message_fa class-attribute

message_fa: str = 'فرمت داده نامعتبر است'

archipy.models.errors.validation_errors.InvalidFormatError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidFormatError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidFormatError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidFormatError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidFormatError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidFormatError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.validation_errors.InvalidFormatError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidEmailError

Bases: BaseError

Exception raised for invalid email formats.

Source code in archipy/models/errors/validation_errors.py
class InvalidEmailError(BaseError):
    """Exception raised for invalid email formats."""

    code: ClassVar[str] = "INVALID_EMAIL"
    message_en: ClassVar[str] = "Invalid email format: {email}"
    message_fa: ClassVar[str] = "فرمت ایمیل نامعتبر است: {email}"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        email: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidEmailError."""
        data = {"email": email} if email else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

    def get_message(self) -> str:
        """Gets the localized error message with email."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        email = self.additional_data.get("email", "email")
        return template.format(email=email)

archipy.models.errors.validation_errors.InvalidEmailError.code class-attribute

code: str = 'INVALID_EMAIL'

archipy.models.errors.validation_errors.InvalidEmailError.message_en class-attribute

message_en: str = 'Invalid email format: {email}'

archipy.models.errors.validation_errors.InvalidEmailError.message_fa class-attribute

message_fa: str = 'فرمت ایمیل نامعتبر است: {email}'

archipy.models.errors.validation_errors.InvalidEmailError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidEmailError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidEmailError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidEmailError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidEmailError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidEmailError.get_message

get_message() -> str

Gets the localized error message with email.

Source code in archipy/models/errors/validation_errors.py
def get_message(self) -> str:
    """Gets the localized error message with email."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    email = self.additional_data.get("email", "email")
    return template.format(email=email)

archipy.models.errors.validation_errors.InvalidEmailError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidPhoneNumberError

Bases: BaseError

Exception raised for invalid phone numbers.

Source code in archipy/models/errors/validation_errors.py
class InvalidPhoneNumberError(BaseError):
    """Exception raised for invalid phone numbers."""

    code: ClassVar[str] = "INVALID_PHONE"
    message_en: ClassVar[str] = "Invalid Iranian phone number: {phone_number}"
    message_fa: ClassVar[str] = "شماره تلفن همراه ایران نامعتبر است: {phone_number}"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        phone_number: str,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidPhoneNumberError."""
        data = {"phone_number": phone_number}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data)

    def get_message(self) -> str:
        """Gets the localized error message with phone number and normalization."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        phone_number = self.additional_data.get("phone_number", "phone_number")
        message = template.format(phone_number=phone_number)

        # Convert numbers to Persian if language is FA
        if self.lang == LanguageType.FA:
            message = message.translate(ENGLISH_TO_PERSIAN_DIGITS_TABLE)

        return message

archipy.models.errors.validation_errors.InvalidPhoneNumberError.code class-attribute

code: str = 'INVALID_PHONE'

archipy.models.errors.validation_errors.InvalidPhoneNumberError.message_en class-attribute

message_en: str = (
    "Invalid Iranian phone number: {phone_number}"
)

archipy.models.errors.validation_errors.InvalidPhoneNumberError.message_fa class-attribute

message_fa: str = (
    "شماره تلفن همراه ایران نامعتبر است: {phone_number}"
)

archipy.models.errors.validation_errors.InvalidPhoneNumberError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidPhoneNumberError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidPhoneNumberError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidPhoneNumberError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidPhoneNumberError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidPhoneNumberError.get_message

get_message() -> str

Gets the localized error message with phone number and normalization.

Source code in archipy/models/errors/validation_errors.py
def get_message(self) -> str:
    """Gets the localized error message with phone number and normalization."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    phone_number = self.additional_data.get("phone_number", "phone_number")
    message = template.format(phone_number=phone_number)

    # Convert numbers to Persian if language is FA
    if self.lang == LanguageType.FA:
        message = message.translate(ENGLISH_TO_PERSIAN_DIGITS_TABLE)

    return message

archipy.models.errors.validation_errors.InvalidPhoneNumberError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidLandlineNumberError

Bases: BaseError

Exception raised for invalid landline numbers.

Source code in archipy/models/errors/validation_errors.py
class InvalidLandlineNumberError(BaseError):
    """Exception raised for invalid landline numbers."""

    code: ClassVar[str] = "INVALID_LANDLINE"
    message_en: ClassVar[str] = "Invalid Iranian landline number: {landline_number}"
    message_fa: ClassVar[str] = "شماره تلفن ثابت ایران نامعتبر است: {landline_number}"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        landline_number: str,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidLandlineNumberError."""
        data = {"landline_number": landline_number}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data)

    def get_message(self) -> str:
        """Gets the localized error message with landline number and normalization."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        landline_number = self.additional_data.get("landline_number", "landline_number")
        message = template.format(landline_number=landline_number)

        # Convert numbers to Persian if language is FA
        if self.lang == LanguageType.FA:
            message = message.translate(ENGLISH_TO_PERSIAN_DIGITS_TABLE)

        return message

archipy.models.errors.validation_errors.InvalidLandlineNumberError.code class-attribute

code: str = 'INVALID_LANDLINE'

archipy.models.errors.validation_errors.InvalidLandlineNumberError.message_en class-attribute

message_en: str = (
    "Invalid Iranian landline number: {landline_number}"
)

archipy.models.errors.validation_errors.InvalidLandlineNumberError.message_fa class-attribute

message_fa: str = (
    "شماره تلفن ثابت ایران نامعتبر است: {landline_number}"
)

archipy.models.errors.validation_errors.InvalidLandlineNumberError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidLandlineNumberError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidLandlineNumberError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidLandlineNumberError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidLandlineNumberError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidLandlineNumberError.get_message

get_message() -> str

Gets the localized error message with landline number and normalization.

Source code in archipy/models/errors/validation_errors.py
def get_message(self) -> str:
    """Gets the localized error message with landline number and normalization."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    landline_number = self.additional_data.get("landline_number", "landline_number")
    message = template.format(landline_number=landline_number)

    # Convert numbers to Persian if language is FA
    if self.lang == LanguageType.FA:
        message = message.translate(ENGLISH_TO_PERSIAN_DIGITS_TABLE)

    return message

archipy.models.errors.validation_errors.InvalidLandlineNumberError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidNationalCodeError

Bases: BaseError

Exception raised for invalid national codes.

Source code in archipy/models/errors/validation_errors.py
class InvalidNationalCodeError(BaseError):
    """Exception raised for invalid national codes."""

    code: ClassVar[str] = "INVALID_NATIONAL_CODE"
    message_en: ClassVar[str] = "Invalid national code format: {national_code}"
    message_fa: ClassVar[str] = "فرمت کد ملی وارد شده اشتباه است: {national_code}"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        national_code: str,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidNationalCodeError."""
        data = {"national_code": national_code}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data)

    def get_message(self) -> str:
        """Gets the localized error message with national code and normalization."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        national_code = self.additional_data.get("national_code", "national_code")
        message = template.format(national_code=national_code)

        # Convert numbers to Persian if language is FA
        if self.lang == LanguageType.FA:
            message = message.translate(ENGLISH_TO_PERSIAN_DIGITS_TABLE)

        return message

archipy.models.errors.validation_errors.InvalidNationalCodeError.code class-attribute

code: str = 'INVALID_NATIONAL_CODE'

archipy.models.errors.validation_errors.InvalidNationalCodeError.message_en class-attribute

message_en: str = (
    "Invalid national code format: {national_code}"
)

archipy.models.errors.validation_errors.InvalidNationalCodeError.message_fa class-attribute

message_fa: str = (
    "فرمت کد ملی وارد شده اشتباه است: {national_code}"
)

archipy.models.errors.validation_errors.InvalidNationalCodeError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidNationalCodeError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidNationalCodeError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidNationalCodeError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidNationalCodeError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidNationalCodeError.get_message

get_message() -> str

Gets the localized error message with national code and normalization.

Source code in archipy/models/errors/validation_errors.py
def get_message(self) -> str:
    """Gets the localized error message with national code and normalization."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    national_code = self.additional_data.get("national_code", "national_code")
    message = template.format(national_code=national_code)

    # Convert numbers to Persian if language is FA
    if self.lang == LanguageType.FA:
        message = message.translate(ENGLISH_TO_PERSIAN_DIGITS_TABLE)

    return message

archipy.models.errors.validation_errors.InvalidNationalCodeError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidPasswordError

Bases: BaseError

Exception raised when a password does not meet the security requirements.

Source code in archipy/models/errors/validation_errors.py
class InvalidPasswordError(BaseError):
    """Exception raised when a password does not meet the security requirements."""

    code: ClassVar[str] = "INVALID_PASSWORD"
    message_en: ClassVar[str] = "Password does not meet the security requirements"
    message_fa: ClassVar[str] = "رمز عبور الزامات امنیتی را برآورده نمی‌کند."
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        requirements: list[str] | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidPasswordError."""
        data = {"requirements": requirements} if requirements else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.validation_errors.InvalidPasswordError.code class-attribute

code: str = 'INVALID_PASSWORD'

archipy.models.errors.validation_errors.InvalidPasswordError.message_en class-attribute

message_en: str = (
    "Password does not meet the security requirements"
)

archipy.models.errors.validation_errors.InvalidPasswordError.message_fa class-attribute

message_fa: str = (
    "رمز عبور الزامات امنیتی را برآورده نمی\u200cکند."
)

archipy.models.errors.validation_errors.InvalidPasswordError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidPasswordError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidPasswordError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidPasswordError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidPasswordError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidPasswordError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.validation_errors.InvalidPasswordError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidDateError

Bases: BaseError

Exception raised for invalid date formats.

Source code in archipy/models/errors/validation_errors.py
class InvalidDateError(BaseError):
    """Exception raised for invalid date formats."""

    code: ClassVar[str] = "INVALID_DATE"
    message_en: ClassVar[str] = "Invalid date format"
    message_fa: ClassVar[str] = "فرمت تاریخ نامعتبر است"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        date: str | None = None,
        expected_format: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidDateError."""
        data = {}
        if date:
            data["date"] = date
        if expected_format:
            data["expected_format"] = expected_format
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.validation_errors.InvalidDateError.code class-attribute

code: str = 'INVALID_DATE'

archipy.models.errors.validation_errors.InvalidDateError.message_en class-attribute

message_en: str = 'Invalid date format'

archipy.models.errors.validation_errors.InvalidDateError.message_fa class-attribute

message_fa: str = 'فرمت تاریخ نامعتبر است'

archipy.models.errors.validation_errors.InvalidDateError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidDateError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidDateError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidDateError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidDateError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidDateError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.validation_errors.InvalidDateError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidUrlError

Bases: BaseError

Exception raised for invalid URL formats.

Source code in archipy/models/errors/validation_errors.py
class InvalidUrlError(BaseError):
    """Exception raised for invalid URL formats."""

    code: ClassVar[str] = "INVALID_URL"
    message_en: ClassVar[str] = "Invalid URL format: {url}"
    message_fa: ClassVar[str] = "فرمت URL نامعتبر است: {url}"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        url: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidUrlError."""
        data = {"url": url} if url else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

    def get_message(self) -> str:
        """Gets the localized error message with URL."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        url = self.additional_data.get("url", "url")
        return template.format(url=url)

archipy.models.errors.validation_errors.InvalidUrlError.code class-attribute

code: str = 'INVALID_URL'

archipy.models.errors.validation_errors.InvalidUrlError.message_en class-attribute

message_en: str = 'Invalid URL format: {url}'

archipy.models.errors.validation_errors.InvalidUrlError.message_fa class-attribute

message_fa: str = 'فرمت URL نامعتبر است: {url}'

archipy.models.errors.validation_errors.InvalidUrlError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidUrlError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidUrlError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidUrlError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidUrlError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidUrlError.get_message

get_message() -> str

Gets the localized error message with URL.

Source code in archipy/models/errors/validation_errors.py
def get_message(self) -> str:
    """Gets the localized error message with URL."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    url = self.additional_data.get("url", "url")
    return template.format(url=url)

archipy.models.errors.validation_errors.InvalidUrlError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidIpError

Bases: BaseError

Exception raised for invalid IP address formats.

Source code in archipy/models/errors/validation_errors.py
class InvalidIpError(BaseError):
    """Exception raised for invalid IP address formats."""

    code: ClassVar[str] = "INVALID_IP"
    message_en: ClassVar[str] = "Invalid IP address format: {ip}"
    message_fa: ClassVar[str] = "فرمت آدرس IP نامعتبر است: {ip}"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        ip: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidIpError."""
        data = {"ip": ip} if ip else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

    def get_message(self) -> str:
        """Gets the localized error message with IP address."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        ip = self.additional_data.get("ip", "ip")
        return template.format(ip=ip)

archipy.models.errors.validation_errors.InvalidIpError.code class-attribute

code: str = 'INVALID_IP'

archipy.models.errors.validation_errors.InvalidIpError.message_en class-attribute

message_en: str = 'Invalid IP address format: {ip}'

archipy.models.errors.validation_errors.InvalidIpError.message_fa class-attribute

message_fa: str = 'فرمت آدرس IP نامعتبر است: {ip}'

archipy.models.errors.validation_errors.InvalidIpError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidIpError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidIpError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidIpError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidIpError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidIpError.get_message

get_message() -> str

Gets the localized error message with IP address.

Source code in archipy/models/errors/validation_errors.py
def get_message(self) -> str:
    """Gets the localized error message with IP address."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    ip = self.additional_data.get("ip", "ip")
    return template.format(ip=ip)

archipy.models.errors.validation_errors.InvalidIpError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidJsonError

Bases: BaseError

Exception raised for invalid JSON formats.

Source code in archipy/models/errors/validation_errors.py
class InvalidJsonError(BaseError):
    """Exception raised for invalid JSON formats."""

    code: ClassVar[str] = "INVALID_JSON"
    message_en: ClassVar[str] = "Invalid JSON format"
    message_fa: ClassVar[str] = "فرمت JSON نامعتبر است"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        json_data: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidJsonError."""
        data = {}
        if json_data:
            data["json_data"] = json_data
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.validation_errors.InvalidJsonError.code class-attribute

code: str = 'INVALID_JSON'

archipy.models.errors.validation_errors.InvalidJsonError.message_en class-attribute

message_en: str = 'Invalid JSON format'

archipy.models.errors.validation_errors.InvalidJsonError.message_fa class-attribute

message_fa: str = 'فرمت JSON نامعتبر است'

archipy.models.errors.validation_errors.InvalidJsonError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidJsonError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidJsonError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidJsonError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidJsonError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidJsonError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.validation_errors.InvalidJsonError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.InvalidTimestampError

Bases: BaseError

Exception raised when a timestamp format is invalid.

Source code in archipy/models/errors/validation_errors.py
class InvalidTimestampError(BaseError):
    """Exception raised when a timestamp format is invalid."""

    code: ClassVar[str] = "INVALID_TIMESTAMP"
    message_en: ClassVar[str] = "Invalid timestamp format"
    message_fa: ClassVar[str] = "فرمت زمان نامعتبر است"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        timestamp: str | None = None,
        expected_format: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidTimestampError."""
        data = {}
        if timestamp:
            data["timestamp"] = timestamp
        if expected_format:
            data["expected_format"] = expected_format
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.validation_errors.InvalidTimestampError.code class-attribute

code: str = 'INVALID_TIMESTAMP'

archipy.models.errors.validation_errors.InvalidTimestampError.message_en class-attribute

message_en: str = 'Invalid timestamp format'

archipy.models.errors.validation_errors.InvalidTimestampError.message_fa class-attribute

message_fa: str = 'فرمت زمان نامعتبر است'

archipy.models.errors.validation_errors.InvalidTimestampError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.InvalidTimestampError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.validation_errors.InvalidTimestampError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.InvalidTimestampError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.InvalidTimestampError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.InvalidTimestampError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.validation_errors.InvalidTimestampError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.validation_errors.OutOfRangeError

Bases: BaseError

Exception raised when a value is out of range.

Source code in archipy/models/errors/validation_errors.py
class OutOfRangeError(BaseError):
    """Exception raised when a value is out of range."""

    code: ClassVar[str] = "OUT_OF_RANGE"
    message_en: ClassVar[str] = "Value is out of acceptable range"
    message_fa: ClassVar[str] = "مقدار خارج از محدوده مجاز است."
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.OUT_OF_RANGE.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.OUT_OF_RANGE.value, tuple)
        else (StatusCode.OUT_OF_RANGE.value if GRPC_AVAILABLE and StatusCode is not None else 11)
    )

    def __init__(
        self,
        field_name: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize OutOfRangeError."""
        data = {"field": field_name} if field_name else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.validation_errors.OutOfRangeError.code class-attribute

code: str = 'OUT_OF_RANGE'

archipy.models.errors.validation_errors.OutOfRangeError.message_en class-attribute

message_en: str = 'Value is out of acceptable range'

archipy.models.errors.validation_errors.OutOfRangeError.message_fa class-attribute

message_fa: str = 'مقدار خارج از محدوده مجاز است.'

archipy.models.errors.validation_errors.OutOfRangeError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.validation_errors.OutOfRangeError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.OUT_OF_RANGE.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.OUT_OF_RANGE.value, tuple)
    else StatusCode.OUT_OF_RANGE.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 11
)

archipy.models.errors.validation_errors.OutOfRangeError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.validation_errors.OutOfRangeError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.validation_errors.OutOfRangeError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.validation_errors.OutOfRangeError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.validation_errors.OutOfRangeError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

options: show_root_toc_entry: false heading_level: 3

Resource Errors

Exceptions for resource lifecycle issues such as not found, already exists, and conflict.

Resource-related error types.

archipy.models.errors.resource_errors.HTTP_AVAILABLE module-attribute

HTTP_AVAILABLE = True

archipy.models.errors.resource_errors.GRPC_AVAILABLE module-attribute

GRPC_AVAILABLE = True

archipy.models.errors.resource_errors.NotFoundError

Bases: BaseError

Exception raised when a resource is not found.

Source code in archipy/models/errors/resource_errors.py
class NotFoundError(BaseError):
    """Exception raised when a resource is not found."""

    code: ClassVar[str] = "NOT_FOUND"
    message_en: ClassVar[str] = "Requested resource not found: {resource_type}"
    message_fa: ClassVar[str] = "منبع درخواستی یافت نشد: {resource_type}"
    http_status: ClassVar[int] = HTTPStatus.NOT_FOUND.value if HTTP_AVAILABLE and HTTPStatus is not None else 404
    grpc_status: ClassVar[int] = (
        StatusCode.NOT_FOUND.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.NOT_FOUND.value, tuple)
        else (StatusCode.NOT_FOUND.value if GRPC_AVAILABLE and StatusCode is not None else 5)
    )

    def __init__(
        self,
        resource_type: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize NotFoundError."""
        data = {"resource_type": resource_type} if resource_type else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

    def get_message(self) -> str:
        """Gets the localized error message with resource type."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        resource_type = self.additional_data.get("resource_type", "resource_type")
        return template.format(resource_type=resource_type)

archipy.models.errors.resource_errors.NotFoundError.code class-attribute

code: str = 'NOT_FOUND'

archipy.models.errors.resource_errors.NotFoundError.message_en class-attribute

message_en: str = (
    "Requested resource not found: {resource_type}"
)

archipy.models.errors.resource_errors.NotFoundError.message_fa class-attribute

message_fa: str = 'منبع درخواستی یافت نشد: {resource_type}'

archipy.models.errors.resource_errors.NotFoundError.http_status class-attribute

http_status: int = (
    HTTPStatus.NOT_FOUND.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 404
)

archipy.models.errors.resource_errors.NotFoundError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.NOT_FOUND.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.NOT_FOUND.value, tuple)
    else StatusCode.NOT_FOUND.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 5
)

archipy.models.errors.resource_errors.NotFoundError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.NotFoundError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.NotFoundError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.NotFoundError.get_message

get_message() -> str

Gets the localized error message with resource type.

Source code in archipy/models/errors/resource_errors.py
def get_message(self) -> str:
    """Gets the localized error message with resource type."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    resource_type = self.additional_data.get("resource_type", "resource_type")
    return template.format(resource_type=resource_type)

archipy.models.errors.resource_errors.NotFoundError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.AlreadyExistsError

Bases: BaseError

Exception raised when a resource already exists.

Source code in archipy/models/errors/resource_errors.py
class AlreadyExistsError(BaseError):
    """Exception raised when a resource already exists."""

    code: ClassVar[str] = "ALREADY_EXISTS"
    message_en: ClassVar[str] = "Resource already exists: {resource_type}"
    message_fa: ClassVar[str] = "منبع از قبل موجود است: {resource_type}"
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.ALREADY_EXISTS.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.ALREADY_EXISTS.value, tuple)
        else (StatusCode.ALREADY_EXISTS.value if GRPC_AVAILABLE and StatusCode is not None else 6)
    )

    def __init__(
        self,
        resource_type: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize AlreadyExistsError."""
        data = {"resource_type": resource_type} if resource_type else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

    def get_message(self) -> str:
        """Gets the localized error message with resource type."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        resource_type = self.additional_data.get("resource_type", "resource_type")
        return template.format(resource_type=resource_type)

archipy.models.errors.resource_errors.AlreadyExistsError.code class-attribute

code: str = 'ALREADY_EXISTS'

archipy.models.errors.resource_errors.AlreadyExistsError.message_en class-attribute

message_en: str = "Resource already exists: {resource_type}"

archipy.models.errors.resource_errors.AlreadyExistsError.message_fa class-attribute

message_fa: str = 'منبع از قبل موجود است: {resource_type}'

archipy.models.errors.resource_errors.AlreadyExistsError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.resource_errors.AlreadyExistsError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.ALREADY_EXISTS.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.ALREADY_EXISTS.value, tuple)
    else StatusCode.ALREADY_EXISTS.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 6
)

archipy.models.errors.resource_errors.AlreadyExistsError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.AlreadyExistsError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.AlreadyExistsError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.AlreadyExistsError.get_message

get_message() -> str

Gets the localized error message with resource type.

Source code in archipy/models/errors/resource_errors.py
def get_message(self) -> str:
    """Gets the localized error message with resource type."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    resource_type = self.additional_data.get("resource_type", "resource_type")
    return template.format(resource_type=resource_type)

archipy.models.errors.resource_errors.AlreadyExistsError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.ConflictError

Bases: BaseError

Exception raised when there is a resource conflict.

Source code in archipy/models/errors/resource_errors.py
class ConflictError(BaseError):
    """Exception raised when there is a resource conflict."""

    code: ClassVar[str] = "CONFLICT"
    message_en: ClassVar[str] = "Resource conflict detected"
    message_fa: ClassVar[str] = "تعارض در منابع تشخیص داده شد"
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.ABORTED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.ABORTED.value, tuple)
        else (StatusCode.ABORTED.value if GRPC_AVAILABLE and StatusCode is not None else 10)
    )

    def __init__(
        self,
        resource_type: str | None = None,
        resource_id: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize ConflictError."""
        data = {}
        if resource_type:
            data["resource_type"] = resource_type
        if resource_id:
            data["resource_id"] = resource_id
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.resource_errors.ConflictError.code class-attribute

code: str = 'CONFLICT'

archipy.models.errors.resource_errors.ConflictError.message_en class-attribute

message_en: str = 'Resource conflict detected'

archipy.models.errors.resource_errors.ConflictError.message_fa class-attribute

message_fa: str = 'تعارض در منابع تشخیص داده شد'

archipy.models.errors.resource_errors.ConflictError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.resource_errors.ConflictError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.ABORTED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.ABORTED.value, tuple)
    else StatusCode.ABORTED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 10
)

archipy.models.errors.resource_errors.ConflictError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.ConflictError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.ConflictError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.ConflictError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.resource_errors.ConflictError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.ResourceLockedError

Bases: BaseError

Exception raised when a resource is locked.

Source code in archipy/models/errors/resource_errors.py
class ResourceLockedError(BaseError):
    """Exception raised when a resource is locked."""

    code: ClassVar[str] = "RESOURCE_LOCKED"
    message_en: ClassVar[str] = "Resource is currently locked"
    message_fa: ClassVar[str] = "منبع در حال حاضر قفل شده است"
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.ABORTED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.ABORTED.value, tuple)
        else (StatusCode.ABORTED.value if GRPC_AVAILABLE and StatusCode is not None else 10)
    )

    def __init__(
        self,
        resource_id: str | None = None,
        lock_owner: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize ResourceLockedError."""
        data = {}
        if resource_id:
            data["resource_id"] = resource_id
        if lock_owner:
            data["lock_owner"] = lock_owner
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.resource_errors.ResourceLockedError.code class-attribute

code: str = 'RESOURCE_LOCKED'

archipy.models.errors.resource_errors.ResourceLockedError.message_en class-attribute

message_en: str = 'Resource is currently locked'

archipy.models.errors.resource_errors.ResourceLockedError.message_fa class-attribute

message_fa: str = 'منبع در حال حاضر قفل شده است'

archipy.models.errors.resource_errors.ResourceLockedError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.resource_errors.ResourceLockedError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.ABORTED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.ABORTED.value, tuple)
    else StatusCode.ABORTED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 10
)

archipy.models.errors.resource_errors.ResourceLockedError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.ResourceLockedError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.ResourceLockedError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.ResourceLockedError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.resource_errors.ResourceLockedError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.ResourceBusyError

Bases: BaseError

Exception raised when a resource is busy.

Source code in archipy/models/errors/resource_errors.py
class ResourceBusyError(BaseError):
    """Exception raised when a resource is busy."""

    code: ClassVar[str] = "RESOURCE_BUSY"
    message_en: ClassVar[str] = "Resource is currently busy"
    message_fa: ClassVar[str] = "منبع در حال حاضر مشغول است"
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.ABORTED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.ABORTED.value, tuple)
        else (StatusCode.ABORTED.value if GRPC_AVAILABLE and StatusCode is not None else 10)
    )

    def __init__(
        self,
        resource_id: str | None = None,
        busy_reason: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize ResourceBusyError."""
        data = {}
        if resource_id:
            data["resource_id"] = resource_id
        if busy_reason:
            data["busy_reason"] = busy_reason
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.resource_errors.ResourceBusyError.code class-attribute

code: str = 'RESOURCE_BUSY'

archipy.models.errors.resource_errors.ResourceBusyError.message_en class-attribute

message_en: str = 'Resource is currently busy'

archipy.models.errors.resource_errors.ResourceBusyError.message_fa class-attribute

message_fa: str = 'منبع در حال حاضر مشغول است'

archipy.models.errors.resource_errors.ResourceBusyError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.resource_errors.ResourceBusyError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.ABORTED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.ABORTED.value, tuple)
    else StatusCode.ABORTED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 10
)

archipy.models.errors.resource_errors.ResourceBusyError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.ResourceBusyError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.ResourceBusyError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.ResourceBusyError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.resource_errors.ResourceBusyError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.DataLossError

Bases: BaseError

Exception raised when data is lost.

Source code in archipy/models/errors/resource_errors.py
class DataLossError(BaseError):
    """Exception raised when data is lost."""

    code: ClassVar[str] = "DATA_LOSS"
    message_en: ClassVar[str] = "Critical data loss detected"
    message_fa: ClassVar[str] = "از دست دادن اطلاعات حیاتی تشخیص داده شد."
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.DATA_LOSS.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.DATA_LOSS.value, tuple)
        else (StatusCode.DATA_LOSS.value if GRPC_AVAILABLE and StatusCode is not None else 15)
    )

archipy.models.errors.resource_errors.DataLossError.code class-attribute

code: str = 'DATA_LOSS'

archipy.models.errors.resource_errors.DataLossError.message_en class-attribute

message_en: str = 'Critical data loss detected'

archipy.models.errors.resource_errors.DataLossError.message_fa class-attribute

message_fa: str = "از دست دادن اطلاعات حیاتی تشخیص داده شد."

archipy.models.errors.resource_errors.DataLossError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.resource_errors.DataLossError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.DATA_LOSS.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.DATA_LOSS.value, tuple)
    else StatusCode.DATA_LOSS.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 15
)

archipy.models.errors.resource_errors.DataLossError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.DataLossError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.DataLossError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.DataLossError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.resource_errors.DataLossError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.InvalidEntityTypeError

Bases: BaseError

Exception raised for invalid entity types.

Source code in archipy/models/errors/resource_errors.py
class InvalidEntityTypeError(BaseError):
    """Exception raised for invalid entity types."""

    code: ClassVar[str] = "INVALID_ENTITY"
    message_en: ClassVar[str] = "Invalid entity type"
    message_fa: ClassVar[str] = "نوع موجودیت نامعتبر است."
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        message: str | None = None,
        expected_type: str | None = None,
        actual_type: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidEntityTypeError."""
        data = {}
        if message:
            data["message"] = message
        if expected_type:
            data["expected_type"] = expected_type
        if actual_type:
            data["actual_type"] = actual_type
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.resource_errors.InvalidEntityTypeError.code class-attribute

code: str = 'INVALID_ENTITY'

archipy.models.errors.resource_errors.InvalidEntityTypeError.message_en class-attribute

message_en: str = 'Invalid entity type'

archipy.models.errors.resource_errors.InvalidEntityTypeError.message_fa class-attribute

message_fa: str = 'نوع موجودیت نامعتبر است.'

archipy.models.errors.resource_errors.InvalidEntityTypeError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.resource_errors.InvalidEntityTypeError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.resource_errors.InvalidEntityTypeError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.InvalidEntityTypeError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.InvalidEntityTypeError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.InvalidEntityTypeError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.resource_errors.InvalidEntityTypeError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.FileTooLargeError

Bases: BaseError

Exception raised when a file is too large.

Source code in archipy/models/errors/resource_errors.py
class FileTooLargeError(BaseError):
    """Exception raised when a file is too large."""

    code: ClassVar[str] = "FILE_TOO_LARGE"
    message_en: ClassVar[str] = "File size exceeds the maximum allowed limit"
    message_fa: ClassVar[str] = "حجم فایل از حد مجاز بیشتر است"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        file_name: str | None = None,
        file_size: int | None = None,
        max_size: int | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize FileTooLargeError."""
        data = {}
        if file_name:
            data["file_name"] = file_name
        if file_size:
            data["file_size"] = file_size
        if max_size:
            data["max_size"] = max_size
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.resource_errors.FileTooLargeError.code class-attribute

code: str = 'FILE_TOO_LARGE'

archipy.models.errors.resource_errors.FileTooLargeError.message_en class-attribute

message_en: str = (
    "File size exceeds the maximum allowed limit"
)

archipy.models.errors.resource_errors.FileTooLargeError.message_fa class-attribute

message_fa: str = 'حجم فایل از حد مجاز بیشتر است'

archipy.models.errors.resource_errors.FileTooLargeError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.resource_errors.FileTooLargeError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.resource_errors.FileTooLargeError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.FileTooLargeError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.FileTooLargeError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.FileTooLargeError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.resource_errors.FileTooLargeError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.InvalidFileTypeError

Bases: BaseError

Exception raised for invalid file types.

Source code in archipy/models/errors/resource_errors.py
class InvalidFileTypeError(BaseError):
    """Exception raised for invalid file types."""

    code: ClassVar[str] = "INVALID_FILE_TYPE"
    message_en: ClassVar[str] = "File type is not supported"
    message_fa: ClassVar[str] = "نوع فایل پشتیبانی نمی‌شود"
    http_status: ClassVar[int] = HTTPStatus.BAD_REQUEST.value if HTTP_AVAILABLE and HTTPStatus is not None else 400
    grpc_status: ClassVar[int] = (
        StatusCode.INVALID_ARGUMENT.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
        else (StatusCode.INVALID_ARGUMENT.value if GRPC_AVAILABLE and StatusCode is not None else 3)
    )

    def __init__(
        self,
        file_name: str | None = None,
        file_type: str | None = None,
        allowed_types: list[str] | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidFileTypeError."""
        data = {}
        if file_name:
            data["file_name"] = file_name
        if file_type:
            data["file_type"] = file_type
        if allowed_types:
            data["allowed_types"] = allowed_types
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.resource_errors.InvalidFileTypeError.code class-attribute

code: str = 'INVALID_FILE_TYPE'

archipy.models.errors.resource_errors.InvalidFileTypeError.message_en class-attribute

message_en: str = 'File type is not supported'

archipy.models.errors.resource_errors.InvalidFileTypeError.message_fa class-attribute

message_fa: str = 'نوع فایل پشتیبانی نمی\u200cشود'

archipy.models.errors.resource_errors.InvalidFileTypeError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_REQUEST.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 400
)

archipy.models.errors.resource_errors.InvalidFileTypeError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INVALID_ARGUMENT.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INVALID_ARGUMENT.value, tuple)
    else StatusCode.INVALID_ARGUMENT.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 3
)

archipy.models.errors.resource_errors.InvalidFileTypeError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.InvalidFileTypeError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.InvalidFileTypeError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.InvalidFileTypeError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.resource_errors.InvalidFileTypeError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.QuotaExceededError

Bases: BaseError

Exception raised when a quota is exceeded.

Source code in archipy/models/errors/resource_errors.py
class QuotaExceededError(BaseError):
    """Exception raised when a quota is exceeded."""

    code: ClassVar[str] = "QUOTA_EXCEEDED"
    message_en: ClassVar[str] = "Storage quota has been exceeded"
    message_fa: ClassVar[str] = "سهمیه ذخیره‌سازی به پایان رسیده است"
    http_status: ClassVar[int] = HTTPStatus.FORBIDDEN.value if HTTP_AVAILABLE and HTTPStatus is not None else 403
    grpc_status: ClassVar[int] = (
        StatusCode.RESOURCE_EXHAUSTED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.RESOURCE_EXHAUSTED.value, tuple)
        else (StatusCode.RESOURCE_EXHAUSTED.value if GRPC_AVAILABLE and StatusCode is not None else 8)
    )

    def __init__(
        self,
        quota_type: str | None = None,
        current_usage: int | None = None,
        quota_limit: int | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize QuotaExceededError."""
        data = {}
        if quota_type:
            data["quota_type"] = quota_type
        if current_usage:
            data["current_usage"] = current_usage
        if quota_limit:
            data["quota_limit"] = quota_limit
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.resource_errors.QuotaExceededError.code class-attribute

code: str = 'QUOTA_EXCEEDED'

archipy.models.errors.resource_errors.QuotaExceededError.message_en class-attribute

message_en: str = 'Storage quota has been exceeded'

archipy.models.errors.resource_errors.QuotaExceededError.message_fa class-attribute

message_fa: str = "سهمیه ذخیره\u200cسازی به پایان رسیده است"

archipy.models.errors.resource_errors.QuotaExceededError.http_status class-attribute

http_status: int = (
    HTTPStatus.FORBIDDEN.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 403
)

archipy.models.errors.resource_errors.QuotaExceededError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.RESOURCE_EXHAUSTED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.RESOURCE_EXHAUSTED.value, tuple
    )
    else StatusCode.RESOURCE_EXHAUSTED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 8
)

archipy.models.errors.resource_errors.QuotaExceededError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.QuotaExceededError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.QuotaExceededError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.QuotaExceededError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.resource_errors.QuotaExceededError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.ResourceExhaustedError

Bases: BaseError

Exception raised when a resource is exhausted.

Source code in archipy/models/errors/resource_errors.py
class ResourceExhaustedError(BaseError):
    """Exception raised when a resource is exhausted."""

    code: ClassVar[str] = "RESOURCE_EXHAUSTED"
    message_en: ClassVar[str] = "Resource limit has been reached"
    message_fa: ClassVar[str] = "محدودیت منابع به پایان رسیده است."
    http_status: ClassVar[int] = (
        HTTPStatus.TOO_MANY_REQUESTS.value if HTTP_AVAILABLE and HTTPStatus is not None else 429
    )
    grpc_status: ClassVar[int] = (
        StatusCode.RESOURCE_EXHAUSTED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.RESOURCE_EXHAUSTED.value, tuple)
        else (StatusCode.RESOURCE_EXHAUSTED.value if GRPC_AVAILABLE and StatusCode is not None else 8)
    )

    def __init__(
        self,
        resource_type: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize ResourceExhaustedError."""
        data = {"resource_type": resource_type} if resource_type else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.resource_errors.ResourceExhaustedError.code class-attribute

code: str = 'RESOURCE_EXHAUSTED'

archipy.models.errors.resource_errors.ResourceExhaustedError.message_en class-attribute

message_en: str = 'Resource limit has been reached'

archipy.models.errors.resource_errors.ResourceExhaustedError.message_fa class-attribute

message_fa: str = 'محدودیت منابع به پایان رسیده است.'

archipy.models.errors.resource_errors.ResourceExhaustedError.http_status class-attribute

http_status: int = (
    HTTPStatus.TOO_MANY_REQUESTS.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 429
)

archipy.models.errors.resource_errors.ResourceExhaustedError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.RESOURCE_EXHAUSTED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.RESOURCE_EXHAUSTED.value, tuple
    )
    else StatusCode.RESOURCE_EXHAUSTED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 8
)

archipy.models.errors.resource_errors.ResourceExhaustedError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.ResourceExhaustedError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.ResourceExhaustedError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.ResourceExhaustedError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.resource_errors.ResourceExhaustedError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.resource_errors.StorageError

Bases: BaseError

Exception raised for storage-related errors.

Source code in archipy/models/errors/resource_errors.py
class StorageError(BaseError):
    """Exception raised for storage-related errors."""

    code: ClassVar[str] = "STORAGE_ERROR"
    message_en: ClassVar[str] = "Storage access error occurred"
    message_fa: ClassVar[str] = "خطا در دسترسی به فضای ذخیره‌سازی"
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

    def __init__(
        self,
        storage_type: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize StorageError."""
        data = {"storage_type": storage_type} if storage_type else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.resource_errors.StorageError.code class-attribute

code: str = 'STORAGE_ERROR'

archipy.models.errors.resource_errors.StorageError.message_en class-attribute

message_en: str = 'Storage access error occurred'

archipy.models.errors.resource_errors.StorageError.message_fa class-attribute

message_fa: str = 'خطا در دسترسی به فضای ذخیره\u200cسازی'

archipy.models.errors.resource_errors.StorageError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.resource_errors.StorageError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.resource_errors.StorageError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.resource_errors.StorageError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.resource_errors.StorageError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.resource_errors.StorageError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.resource_errors.StorageError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

options: show_root_toc_entry: false heading_level: 3

Business Errors

Exceptions representing violations of business rules and domain constraints.

Business-rule error types.

archipy.models.errors.business_errors.HTTP_AVAILABLE module-attribute

HTTP_AVAILABLE = True

archipy.models.errors.business_errors.GRPC_AVAILABLE module-attribute

GRPC_AVAILABLE = True

archipy.models.errors.business_errors.InvalidStateError

Bases: BaseError

Exception raised when an operation is attempted in an invalid state.

Source code in archipy/models/errors/business_errors.py
class InvalidStateError(BaseError):
    """Exception raised when an operation is attempted in an invalid state."""

    code: ClassVar[str] = "INVALID_STATE"
    message_en: ClassVar[str] = "Invalid state for the requested operation"
    message_fa: ClassVar[str] = "وضعیت نامعتبر برای عملیات درخواستی"
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.FAILED_PRECONDITION.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.FAILED_PRECONDITION.value, tuple)
        else (StatusCode.FAILED_PRECONDITION.value if GRPC_AVAILABLE and StatusCode is not None else 9)
    )

    def __init__(
        self,
        current_state: str | None = None,
        expected_state: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidStateError."""
        data = {}
        if current_state:
            data["current_state"] = current_state
        if expected_state:
            data["expected_state"] = expected_state
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.business_errors.InvalidStateError.code class-attribute

code: str = 'INVALID_STATE'

archipy.models.errors.business_errors.InvalidStateError.message_en class-attribute

message_en: str = (
    "Invalid state for the requested operation"
)

archipy.models.errors.business_errors.InvalidStateError.message_fa class-attribute

message_fa: str = 'وضعیت نامعتبر برای عملیات درخواستی'

archipy.models.errors.business_errors.InvalidStateError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.business_errors.InvalidStateError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.FAILED_PRECONDITION.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.FAILED_PRECONDITION.value, tuple
    )
    else StatusCode.FAILED_PRECONDITION.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 9
)

archipy.models.errors.business_errors.InvalidStateError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.business_errors.InvalidStateError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.business_errors.InvalidStateError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.business_errors.InvalidStateError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.business_errors.InvalidStateError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.business_errors.FailedPreconditionError

Bases: BaseError

Exception raised when a precondition for an operation is not met.

Source code in archipy/models/errors/business_errors.py
class FailedPreconditionError(BaseError):
    """Exception raised when a precondition for an operation is not met."""

    code: ClassVar[str] = "FAILED_PRECONDITION"
    message_en: ClassVar[str] = "Operation preconditions not met"
    message_fa: ClassVar[str] = "پیش‌نیازهای عملیات برآورده نشده است."
    http_status: ClassVar[int] = (
        HTTPStatus.PRECONDITION_FAILED.value if HTTP_AVAILABLE and HTTPStatus is not None else 412
    )
    grpc_status: ClassVar[int] = (
        StatusCode.FAILED_PRECONDITION.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.FAILED_PRECONDITION.value, tuple)
        else (StatusCode.FAILED_PRECONDITION.value if GRPC_AVAILABLE and StatusCode is not None else 9)
    )

    def __init__(
        self,
        precondition: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize FailedPreconditionError."""
        data = {}
        if precondition:
            data["precondition"] = precondition
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.business_errors.FailedPreconditionError.code class-attribute

code: str = 'FAILED_PRECONDITION'

archipy.models.errors.business_errors.FailedPreconditionError.message_en class-attribute

message_en: str = 'Operation preconditions not met'

archipy.models.errors.business_errors.FailedPreconditionError.message_fa class-attribute

message_fa: str = (
    "پیش\u200cنیازهای عملیات برآورده نشده است."
)

archipy.models.errors.business_errors.FailedPreconditionError.http_status class-attribute

http_status: int = (
    HTTPStatus.PRECONDITION_FAILED.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 412
)

archipy.models.errors.business_errors.FailedPreconditionError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.FAILED_PRECONDITION.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.FAILED_PRECONDITION.value, tuple
    )
    else StatusCode.FAILED_PRECONDITION.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 9
)

archipy.models.errors.business_errors.FailedPreconditionError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.business_errors.FailedPreconditionError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.business_errors.FailedPreconditionError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.business_errors.FailedPreconditionError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.business_errors.FailedPreconditionError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.business_errors.BusinessRuleViolationError

Bases: BaseError

Exception raised when a business rule is violated.

Source code in archipy/models/errors/business_errors.py
class BusinessRuleViolationError(BaseError):
    """Exception raised when a business rule is violated."""

    code: ClassVar[str] = "BUSINESS_RULE_VIOLATION"
    message_en: ClassVar[str] = "Business rule violation"
    message_fa: ClassVar[str] = "نقض قوانین کسب و کار"
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.FAILED_PRECONDITION.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.FAILED_PRECONDITION.value, tuple)
        else (StatusCode.FAILED_PRECONDITION.value if GRPC_AVAILABLE and StatusCode is not None else 9)
    )

    def __init__(
        self,
        rule: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize BusinessRuleViolationError."""
        data = {}
        if rule:
            data["rule"] = rule
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.business_errors.BusinessRuleViolationError.code class-attribute

code: str = 'BUSINESS_RULE_VIOLATION'

archipy.models.errors.business_errors.BusinessRuleViolationError.message_en class-attribute

message_en: str = 'Business rule violation'

archipy.models.errors.business_errors.BusinessRuleViolationError.message_fa class-attribute

message_fa: str = 'نقض قوانین کسب و کار'

archipy.models.errors.business_errors.BusinessRuleViolationError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.business_errors.BusinessRuleViolationError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.FAILED_PRECONDITION.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.FAILED_PRECONDITION.value, tuple
    )
    else StatusCode.FAILED_PRECONDITION.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 9
)

archipy.models.errors.business_errors.BusinessRuleViolationError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.business_errors.BusinessRuleViolationError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.business_errors.BusinessRuleViolationError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.business_errors.BusinessRuleViolationError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.business_errors.BusinessRuleViolationError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.business_errors.InvalidOperationError

Bases: BaseError

Exception raised when an operation is not allowed in the current context.

Source code in archipy/models/errors/business_errors.py
class InvalidOperationError(BaseError):
    """Exception raised when an operation is not allowed in the current context."""

    code: ClassVar[str] = "INVALID_OPERATION"
    message_en: ClassVar[str] = "Operation is not allowed in the current context"
    message_fa: ClassVar[str] = "عملیات در وضعیت فعلی مجاز نیست"
    http_status: ClassVar[int] = HTTPStatus.FORBIDDEN.value if HTTP_AVAILABLE and HTTPStatus is not None else 403
    grpc_status: ClassVar[int] = (
        StatusCode.PERMISSION_DENIED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.PERMISSION_DENIED.value, tuple)
        else (StatusCode.PERMISSION_DENIED.value if GRPC_AVAILABLE and StatusCode is not None else 7)
    )

    def __init__(
        self,
        operation: str | None = None,
        context: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InvalidOperationError."""
        data = {}
        if operation:
            data["operation"] = operation
        if context:
            data["context"] = context
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.business_errors.InvalidOperationError.code class-attribute

code: str = 'INVALID_OPERATION'

archipy.models.errors.business_errors.InvalidOperationError.message_en class-attribute

message_en: str = (
    "Operation is not allowed in the current context"
)

archipy.models.errors.business_errors.InvalidOperationError.message_fa class-attribute

message_fa: str = 'عملیات در وضعیت فعلی مجاز نیست'

archipy.models.errors.business_errors.InvalidOperationError.http_status class-attribute

http_status: int = (
    HTTPStatus.FORBIDDEN.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 403
)

archipy.models.errors.business_errors.InvalidOperationError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.PERMISSION_DENIED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.PERMISSION_DENIED.value, tuple
    )
    else StatusCode.PERMISSION_DENIED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 7
)

archipy.models.errors.business_errors.InvalidOperationError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.business_errors.InvalidOperationError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.business_errors.InvalidOperationError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.business_errors.InvalidOperationError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.business_errors.InvalidOperationError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.business_errors.InsufficientFundsError

Bases: BaseError

Exception raised when there are insufficient funds for an operation.

Source code in archipy/models/errors/business_errors.py
class InsufficientFundsError(BaseError):
    """Exception raised when there are insufficient funds for an operation."""

    code: ClassVar[str] = "INSUFFICIENT_FUNDS"
    message_en: ClassVar[str] = "Insufficient funds for the operation"
    message_fa: ClassVar[str] = "موجودی ناکافی برای عملیات"
    http_status: ClassVar[int] = HTTPStatus.PAYMENT_REQUIRED.value if HTTP_AVAILABLE and HTTPStatus is not None else 402
    grpc_status: ClassVar[int] = (
        StatusCode.FAILED_PRECONDITION.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.FAILED_PRECONDITION.value, tuple)
        else (StatusCode.FAILED_PRECONDITION.value if GRPC_AVAILABLE and StatusCode is not None else 9)
    )

archipy.models.errors.business_errors.InsufficientFundsError.code class-attribute

code: str = 'INSUFFICIENT_FUNDS'

archipy.models.errors.business_errors.InsufficientFundsError.message_en class-attribute

message_en: str = 'Insufficient funds for the operation'

archipy.models.errors.business_errors.InsufficientFundsError.message_fa class-attribute

message_fa: str = 'موجودی ناکافی برای عملیات'

archipy.models.errors.business_errors.InsufficientFundsError.http_status class-attribute

http_status: int = (
    HTTPStatus.PAYMENT_REQUIRED.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 402
)

archipy.models.errors.business_errors.InsufficientFundsError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.FAILED_PRECONDITION.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.FAILED_PRECONDITION.value, tuple
    )
    else StatusCode.FAILED_PRECONDITION.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 9
)

archipy.models.errors.business_errors.InsufficientFundsError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.business_errors.InsufficientFundsError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.business_errors.InsufficientFundsError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.business_errors.InsufficientFundsError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.business_errors.InsufficientFundsError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.business_errors.InsufficientBalanceError

Bases: BaseError

Exception raised when an operation fails due to insufficient account balance.

Source code in archipy/models/errors/business_errors.py
class InsufficientBalanceError(BaseError):
    """Exception raised when an operation fails due to insufficient account balance."""

    code: ClassVar[str] = "INSUFFICIENT_BALANCE"
    message_en: ClassVar[str] = "Insufficient balance for operation"
    message_fa: ClassVar[str] = "عدم موجودی کافی برای عملیات."
    http_status: ClassVar[int] = HTTPStatus.PAYMENT_REQUIRED.value if HTTP_AVAILABLE and HTTPStatus is not None else 402
    grpc_status: ClassVar[int] = (
        StatusCode.FAILED_PRECONDITION.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.FAILED_PRECONDITION.value, tuple)
        else (StatusCode.FAILED_PRECONDITION.value if GRPC_AVAILABLE and StatusCode is not None else 9)
    )

archipy.models.errors.business_errors.InsufficientBalanceError.code class-attribute

code: str = 'INSUFFICIENT_BALANCE'

archipy.models.errors.business_errors.InsufficientBalanceError.message_en class-attribute

message_en: str = 'Insufficient balance for operation'

archipy.models.errors.business_errors.InsufficientBalanceError.message_fa class-attribute

message_fa: str = 'عدم موجودی کافی برای عملیات.'

archipy.models.errors.business_errors.InsufficientBalanceError.http_status class-attribute

http_status: int = (
    HTTPStatus.PAYMENT_REQUIRED.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 402
)

archipy.models.errors.business_errors.InsufficientBalanceError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.FAILED_PRECONDITION.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.FAILED_PRECONDITION.value, tuple
    )
    else StatusCode.FAILED_PRECONDITION.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 9
)

archipy.models.errors.business_errors.InsufficientBalanceError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.business_errors.InsufficientBalanceError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.business_errors.InsufficientBalanceError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.business_errors.InsufficientBalanceError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.business_errors.InsufficientBalanceError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.business_errors.MaintenanceModeError

Bases: BaseError

Exception raised when the system is in maintenance mode.

Source code in archipy/models/errors/business_errors.py
class MaintenanceModeError(BaseError):
    """Exception raised when the system is in maintenance mode."""

    code: ClassVar[str] = "MAINTENANCE_MODE"
    message_en: ClassVar[str] = "System is currently in maintenance mode"
    message_fa: ClassVar[str] = "سیستم در حال حاضر در حالت تعمیر و نگهداری است"
    http_status: ClassVar[int] = (
        HTTPStatus.SERVICE_UNAVAILABLE.value if HTTP_AVAILABLE and HTTPStatus is not None else 503
    )
    grpc_status: ClassVar[int] = (
        StatusCode.UNAVAILABLE.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAVAILABLE.value, tuple)
        else (StatusCode.UNAVAILABLE.value if GRPC_AVAILABLE and StatusCode is not None else 14)
    )

    def __init__(
        self,
        estimated_duration: int | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize MaintenanceModeError."""
        data = {"estimated_duration": estimated_duration} if estimated_duration else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.business_errors.MaintenanceModeError.code class-attribute

code: str = 'MAINTENANCE_MODE'

archipy.models.errors.business_errors.MaintenanceModeError.message_en class-attribute

message_en: str = 'System is currently in maintenance mode'

archipy.models.errors.business_errors.MaintenanceModeError.message_fa class-attribute

message_fa: str = (
    "سیستم در حال حاضر در حالت تعمیر و نگهداری است"
)

archipy.models.errors.business_errors.MaintenanceModeError.http_status class-attribute

http_status: int = (
    HTTPStatus.SERVICE_UNAVAILABLE.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 503
)

archipy.models.errors.business_errors.MaintenanceModeError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAVAILABLE.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAVAILABLE.value, tuple)
    else StatusCode.UNAVAILABLE.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 14
)

archipy.models.errors.business_errors.MaintenanceModeError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.business_errors.MaintenanceModeError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.business_errors.MaintenanceModeError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.business_errors.MaintenanceModeError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.business_errors.MaintenanceModeError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

options: show_root_toc_entry: false heading_level: 3

Network Errors

Exceptions for network communication failures including timeouts and connectivity issues.

Network-related error types.

archipy.models.errors.network_errors.HTTP_AVAILABLE module-attribute

HTTP_AVAILABLE = True

archipy.models.errors.network_errors.GRPC_AVAILABLE module-attribute

GRPC_AVAILABLE = True

archipy.models.errors.network_errors.NetworkError

Bases: BaseError

Exception raised for network-related errors.

Source code in archipy/models/errors/network_errors.py
class NetworkError(BaseError):
    """Exception raised for network-related errors."""

    code: ClassVar[str] = "NETWORK_ERROR"
    message_en: ClassVar[str] = "Network error occurred"
    message_fa: ClassVar[str] = "خطای شبکه رخ داده است"
    http_status: ClassVar[int] = HTTPStatus.BAD_GATEWAY.value if HTTP_AVAILABLE and HTTPStatus is not None else 502
    grpc_status: ClassVar[int] = (
        StatusCode.UNAVAILABLE.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAVAILABLE.value, tuple)
        else (StatusCode.UNAVAILABLE.value if GRPC_AVAILABLE and StatusCode is not None else 14)
    )

    def __init__(
        self,
        service: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize NetworkError."""
        data = {}
        if service:
            data["service"] = service
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.network_errors.NetworkError.code class-attribute

code: str = 'NETWORK_ERROR'

archipy.models.errors.network_errors.NetworkError.message_en class-attribute

message_en: str = 'Network error occurred'

archipy.models.errors.network_errors.NetworkError.message_fa class-attribute

message_fa: str = 'خطای شبکه رخ داده است'

archipy.models.errors.network_errors.NetworkError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_GATEWAY.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 502
)

archipy.models.errors.network_errors.NetworkError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAVAILABLE.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAVAILABLE.value, tuple)
    else StatusCode.UNAVAILABLE.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 14
)

archipy.models.errors.network_errors.NetworkError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.network_errors.NetworkError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.network_errors.NetworkError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.network_errors.NetworkError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.network_errors.NetworkError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.network_errors.ConnectionTimeoutError

Bases: BaseError

Exception raised when a connection times out.

Source code in archipy/models/errors/network_errors.py
class ConnectionTimeoutError(BaseError):
    """Exception raised when a connection times out."""

    code: ClassVar[str] = "CONNECTION_TIMEOUT"
    message_en: ClassVar[str] = "Connection timed out"
    message_fa: ClassVar[str] = "اتصال با تایم‌اوت مواجه شد"
    http_status: ClassVar[int] = HTTPStatus.REQUEST_TIMEOUT.value if HTTP_AVAILABLE and HTTPStatus is not None else 408
    grpc_status: ClassVar[int] = (
        StatusCode.DEADLINE_EXCEEDED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.DEADLINE_EXCEEDED.value, tuple)
        else (StatusCode.DEADLINE_EXCEEDED.value if GRPC_AVAILABLE and StatusCode is not None else 4)
    )

    def __init__(
        self,
        service: str | None = None,
        timeout: int | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize ConnectionTimeoutError."""
        data = {}
        if service:
            data["service"] = service
        if timeout:
            data["timeout"] = timeout
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.network_errors.ConnectionTimeoutError.code class-attribute

code: str = 'CONNECTION_TIMEOUT'

archipy.models.errors.network_errors.ConnectionTimeoutError.message_en class-attribute

message_en: str = 'Connection timed out'

archipy.models.errors.network_errors.ConnectionTimeoutError.message_fa class-attribute

message_fa: str = 'اتصال با تایم\u200cاوت مواجه شد'

archipy.models.errors.network_errors.ConnectionTimeoutError.http_status class-attribute

http_status: int = (
    HTTPStatus.REQUEST_TIMEOUT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 408
)

archipy.models.errors.network_errors.ConnectionTimeoutError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.DEADLINE_EXCEEDED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.DEADLINE_EXCEEDED.value, tuple
    )
    else StatusCode.DEADLINE_EXCEEDED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 4
)

archipy.models.errors.network_errors.ConnectionTimeoutError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.network_errors.ConnectionTimeoutError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.network_errors.ConnectionTimeoutError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.network_errors.ConnectionTimeoutError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.network_errors.ConnectionTimeoutError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.network_errors.ServiceUnavailableError

Bases: BaseError

Exception raised when a service is unavailable.

Source code in archipy/models/errors/network_errors.py
class ServiceUnavailableError(BaseError):
    """Exception raised when a service is unavailable."""

    code: ClassVar[str] = "SERVICE_UNAVAILABLE"
    message_en: ClassVar[str] = "Service is currently unavailable"
    message_fa: ClassVar[str] = "سرویس در حال حاضر در دسترس نیست"
    http_status: ClassVar[int] = (
        HTTPStatus.SERVICE_UNAVAILABLE.value if HTTP_AVAILABLE and HTTPStatus is not None else 503
    )
    grpc_status: ClassVar[int] = (
        StatusCode.UNAVAILABLE.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAVAILABLE.value, tuple)
        else (StatusCode.UNAVAILABLE.value if GRPC_AVAILABLE and StatusCode is not None else 14)
    )

    def __init__(
        self,
        service: str | None = None,
        retry_after: int | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize ServiceUnavailableError."""
        data = {}
        if service:
            data["service"] = service
        if retry_after:
            data["retry_after"] = retry_after
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.network_errors.ServiceUnavailableError.code class-attribute

code: str = 'SERVICE_UNAVAILABLE'

archipy.models.errors.network_errors.ServiceUnavailableError.message_en class-attribute

message_en: str = 'Service is currently unavailable'

archipy.models.errors.network_errors.ServiceUnavailableError.message_fa class-attribute

message_fa: str = 'سرویس در حال حاضر در دسترس نیست'

archipy.models.errors.network_errors.ServiceUnavailableError.http_status class-attribute

http_status: int = (
    HTTPStatus.SERVICE_UNAVAILABLE.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 503
)

archipy.models.errors.network_errors.ServiceUnavailableError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAVAILABLE.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAVAILABLE.value, tuple)
    else StatusCode.UNAVAILABLE.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 14
)

archipy.models.errors.network_errors.ServiceUnavailableError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.network_errors.ServiceUnavailableError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.network_errors.ServiceUnavailableError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.network_errors.ServiceUnavailableError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.network_errors.ServiceUnavailableError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.network_errors.GatewayTimeoutError

Bases: BaseError

Exception raised when a gateway times out.

Source code in archipy/models/errors/network_errors.py
class GatewayTimeoutError(BaseError):
    """Exception raised when a gateway times out."""

    code: ClassVar[str] = "GATEWAY_TIMEOUT"
    message_en: ClassVar[str] = "Gateway timeout"
    message_fa: ClassVar[str] = "تایم‌اوت دروازه"
    http_status: ClassVar[int] = HTTPStatus.GATEWAY_TIMEOUT.value if HTTP_AVAILABLE and HTTPStatus is not None else 504
    grpc_status: ClassVar[int] = (
        StatusCode.DEADLINE_EXCEEDED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.DEADLINE_EXCEEDED.value, tuple)
        else (StatusCode.DEADLINE_EXCEEDED.value if GRPC_AVAILABLE and StatusCode is not None else 4)
    )

    def __init__(
        self,
        gateway: str | None = None,
        timeout: int | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize GatewayTimeoutError."""
        data = {}
        if gateway:
            data["gateway"] = gateway
        if timeout:
            data["timeout"] = timeout
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.network_errors.GatewayTimeoutError.code class-attribute

code: str = 'GATEWAY_TIMEOUT'

archipy.models.errors.network_errors.GatewayTimeoutError.message_en class-attribute

message_en: str = 'Gateway timeout'

archipy.models.errors.network_errors.GatewayTimeoutError.message_fa class-attribute

message_fa: str = 'تایم\u200cاوت دروازه'

archipy.models.errors.network_errors.GatewayTimeoutError.http_status class-attribute

http_status: int = (
    HTTPStatus.GATEWAY_TIMEOUT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 504
)

archipy.models.errors.network_errors.GatewayTimeoutError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.DEADLINE_EXCEEDED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.DEADLINE_EXCEEDED.value, tuple
    )
    else StatusCode.DEADLINE_EXCEEDED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 4
)

archipy.models.errors.network_errors.GatewayTimeoutError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.network_errors.GatewayTimeoutError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.network_errors.GatewayTimeoutError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.network_errors.GatewayTimeoutError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.network_errors.GatewayTimeoutError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.network_errors.BadGatewayError

Bases: BaseError

Exception raised when a gateway returns an invalid response.

Source code in archipy/models/errors/network_errors.py
class BadGatewayError(BaseError):
    """Exception raised when a gateway returns an invalid response."""

    code: ClassVar[str] = "BAD_GATEWAY"
    message_en: ClassVar[str] = "Bad gateway"
    message_fa: ClassVar[str] = "دروازه نامعتبر"
    http_status: ClassVar[int] = HTTPStatus.BAD_GATEWAY.value if HTTP_AVAILABLE and HTTPStatus is not None else 502
    grpc_status: ClassVar[int] = (
        StatusCode.UNAVAILABLE.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAVAILABLE.value, tuple)
        else (StatusCode.UNAVAILABLE.value if GRPC_AVAILABLE and StatusCode is not None else 14)
    )

    def __init__(
        self,
        gateway: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize BadGatewayError."""
        data = {}
        if gateway:
            data["gateway"] = gateway
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.network_errors.BadGatewayError.code class-attribute

code: str = 'BAD_GATEWAY'

archipy.models.errors.network_errors.BadGatewayError.message_en class-attribute

message_en: str = 'Bad gateway'

archipy.models.errors.network_errors.BadGatewayError.message_fa class-attribute

message_fa: str = 'دروازه نامعتبر'

archipy.models.errors.network_errors.BadGatewayError.http_status class-attribute

http_status: int = (
    HTTPStatus.BAD_GATEWAY.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 502
)

archipy.models.errors.network_errors.BadGatewayError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAVAILABLE.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAVAILABLE.value, tuple)
    else StatusCode.UNAVAILABLE.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 14
)

archipy.models.errors.network_errors.BadGatewayError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.network_errors.BadGatewayError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.network_errors.BadGatewayError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.network_errors.BadGatewayError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.network_errors.BadGatewayError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.network_errors.RateLimitExceededError

Bases: BaseError

Exception raised when a rate limit is exceeded.

Source code in archipy/models/errors/network_errors.py
class RateLimitExceededError(BaseError):
    """Exception raised when a rate limit is exceeded."""

    code: ClassVar[str] = "RATE_LIMIT_EXCEEDED"
    message_en: ClassVar[str] = "Rate limit has been exceeded"
    message_fa: ClassVar[str] = "محدودیت نرخ درخواست به پایان رسیده است"
    http_status: ClassVar[int] = (
        HTTPStatus.TOO_MANY_REQUESTS.value if HTTP_AVAILABLE and HTTPStatus is not None else 429
    )
    grpc_status: ClassVar[int] = (
        StatusCode.RESOURCE_EXHAUSTED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.RESOURCE_EXHAUSTED.value, tuple)
        else (StatusCode.RESOURCE_EXHAUSTED.value if GRPC_AVAILABLE and StatusCode is not None else 8)
    )

    def __init__(
        self,
        rate_limit_type: str | None = None,
        retry_after: int | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize RateLimitExceededError."""
        data = {}
        if rate_limit_type:
            data["rate_limit_type"] = rate_limit_type
        if retry_after:
            data["retry_after"] = retry_after
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.network_errors.RateLimitExceededError.code class-attribute

code: str = 'RATE_LIMIT_EXCEEDED'

archipy.models.errors.network_errors.RateLimitExceededError.message_en class-attribute

message_en: str = 'Rate limit has been exceeded'

archipy.models.errors.network_errors.RateLimitExceededError.message_fa class-attribute

message_fa: str = 'محدودیت نرخ درخواست به پایان رسیده است'

archipy.models.errors.network_errors.RateLimitExceededError.http_status class-attribute

http_status: int = (
    HTTPStatus.TOO_MANY_REQUESTS.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 429
)

archipy.models.errors.network_errors.RateLimitExceededError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.RESOURCE_EXHAUSTED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.RESOURCE_EXHAUSTED.value, tuple
    )
    else StatusCode.RESOURCE_EXHAUSTED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 8
)

archipy.models.errors.network_errors.RateLimitExceededError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.network_errors.RateLimitExceededError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.network_errors.RateLimitExceededError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.network_errors.RateLimitExceededError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.network_errors.RateLimitExceededError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

options: show_root_toc_entry: false heading_level: 3

Database Errors

Exceptions for database-level failures including connection errors, constraint violations, and transaction failures.

Database-related error types.

archipy.models.errors.database_errors.HTTP_AVAILABLE module-attribute

HTTP_AVAILABLE = True

archipy.models.errors.database_errors.GRPC_AVAILABLE module-attribute

GRPC_AVAILABLE = True

archipy.models.errors.database_errors.DatabaseError

Bases: BaseError

Base class for all database-related errors.

Source code in archipy/models/errors/database_errors.py
class DatabaseError(BaseError):
    """Base class for all database-related errors."""

    code: ClassVar[str] = "DATABASE_ERROR"
    retryable: ClassVar[bool] = False
    message_en: ClassVar[str] = "Database error occurred"
    message_fa: ClassVar[str] = "خطای پایگاه داده رخ داده است"
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

    def __init__(
        self,
        database: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize DatabaseError."""
        data = {}
        if database:
            data["database"] = database
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.database_errors.DatabaseError.code class-attribute

code: str = 'DATABASE_ERROR'

archipy.models.errors.database_errors.DatabaseError.retryable class-attribute

retryable: bool = False

archipy.models.errors.database_errors.DatabaseError.message_en class-attribute

message_en: str = 'Database error occurred'

archipy.models.errors.database_errors.DatabaseError.message_fa class-attribute

message_fa: str = 'خطای پایگاه داده رخ داده است'

archipy.models.errors.database_errors.DatabaseError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.database_errors.DatabaseError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.database_errors.DatabaseError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseQueryError

Bases: DatabaseError

Exception raised for database query errors.

Source code in archipy/models/errors/database_errors.py
class DatabaseQueryError(DatabaseError):
    """Exception raised for database query errors."""

    code: ClassVar[str] = "DATABASE_QUERY_ERROR"
    message_en: ClassVar[str] = "Error executing database query"
    message_fa: ClassVar[str] = "خطا در اجرای پرس و جوی پایگاه داده"
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

    def __init__(
        self,
        database: str | None = None,
        query: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize DatabaseQueryError."""
        data = {}
        if query:
            data["query"] = query
        if additional_data:
            data.update(additional_data)
        super().__init__(database=database, lang=lang, additional_data=data or None)

archipy.models.errors.database_errors.DatabaseQueryError.code class-attribute

code: str = 'DATABASE_QUERY_ERROR'

archipy.models.errors.database_errors.DatabaseQueryError.message_en class-attribute

message_en: str = 'Error executing database query'

archipy.models.errors.database_errors.DatabaseQueryError.message_fa class-attribute

message_fa: str = 'خطا در اجرای پرس و جوی پایگاه داده'

archipy.models.errors.database_errors.DatabaseQueryError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.database_errors.DatabaseQueryError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.database_errors.DatabaseQueryError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseQueryError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseQueryError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseQueryError.retryable class-attribute

retryable: bool = False

archipy.models.errors.database_errors.DatabaseQueryError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseQueryError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseConnectionError

Bases: DatabaseQueryError

Exception raised for database connection errors.

Source code in archipy/models/errors/database_errors.py
class DatabaseConnectionError(DatabaseQueryError):
    """Exception raised for database connection errors."""

    code: ClassVar[str] = "DATABASE_CONNECTION_ERROR"
    message_en: ClassVar[str] = "Failed to connect to the database"
    message_fa: ClassVar[str] = "خطا در اتصال به پایگاه داده"
    http_status: ClassVar[int] = (
        HTTPStatus.SERVICE_UNAVAILABLE.value if HTTP_AVAILABLE and HTTPStatus is not None else 503
    )
    grpc_status: ClassVar[int] = (
        StatusCode.UNAVAILABLE.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAVAILABLE.value, tuple)
        else (StatusCode.UNAVAILABLE.value if GRPC_AVAILABLE and StatusCode is not None else 14)
    )

archipy.models.errors.database_errors.DatabaseConnectionError.code class-attribute

code: str = 'DATABASE_CONNECTION_ERROR'

archipy.models.errors.database_errors.DatabaseConnectionError.message_en class-attribute

message_en: str = 'Failed to connect to the database'

archipy.models.errors.database_errors.DatabaseConnectionError.message_fa class-attribute

message_fa: str = 'خطا در اتصال به پایگاه داده'

archipy.models.errors.database_errors.DatabaseConnectionError.http_status class-attribute

http_status: int = (
    HTTPStatus.SERVICE_UNAVAILABLE.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 503
)

archipy.models.errors.database_errors.DatabaseConnectionError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAVAILABLE.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAVAILABLE.value, tuple)
    else StatusCode.UNAVAILABLE.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 14
)

archipy.models.errors.database_errors.DatabaseConnectionError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseConnectionError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseConnectionError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseConnectionError.retryable class-attribute

retryable: bool = False

archipy.models.errors.database_errors.DatabaseConnectionError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseConnectionError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseTransactionError

Bases: DatabaseError

Exception raised for database transaction errors.

Source code in archipy/models/errors/database_errors.py
class DatabaseTransactionError(DatabaseError):
    """Exception raised for database transaction errors."""

    code: ClassVar[str] = "DATABASE_TRANSACTION_ERROR"
    message_en: ClassVar[str] = "Error in database transaction"
    message_fa: ClassVar[str] = "خطا در تراکنش پایگاه داده"
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

    def __init__(
        self,
        database: str | None = None,
        transaction_id: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize DatabaseTransactionError."""
        data = {}
        if transaction_id:
            data["transaction_id"] = transaction_id
        if additional_data:
            data.update(additional_data)
        super().__init__(database=database, lang=lang, additional_data=data or None)

archipy.models.errors.database_errors.DatabaseTransactionError.code class-attribute

code: str = 'DATABASE_TRANSACTION_ERROR'

archipy.models.errors.database_errors.DatabaseTransactionError.message_en class-attribute

message_en: str = 'Error in database transaction'

archipy.models.errors.database_errors.DatabaseTransactionError.message_fa class-attribute

message_fa: str = 'خطا در تراکنش پایگاه داده'

archipy.models.errors.database_errors.DatabaseTransactionError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.database_errors.DatabaseTransactionError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.database_errors.DatabaseTransactionError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseTransactionError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseTransactionError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseTransactionError.retryable class-attribute

retryable: bool = False

archipy.models.errors.database_errors.DatabaseTransactionError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseTransactionError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseTimeoutError

Bases: DatabaseQueryError

Exception raised for database timeout errors.

Source code in archipy/models/errors/database_errors.py
class DatabaseTimeoutError(DatabaseQueryError):
    """Exception raised for database timeout errors."""

    code: ClassVar[str] = "DATABASE_TIMEOUT_ERROR"
    message_en: ClassVar[str] = "Database operation timed out"
    message_fa: ClassVar[str] = "عملیات پایگاه داده با تایم‌اوت مواجه شد"
    http_status: ClassVar[int] = HTTPStatus.REQUEST_TIMEOUT.value if HTTP_AVAILABLE and HTTPStatus is not None else 408
    grpc_status: ClassVar[int] = (
        StatusCode.DEADLINE_EXCEEDED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.DEADLINE_EXCEEDED.value, tuple)
        else (StatusCode.DEADLINE_EXCEEDED.value if GRPC_AVAILABLE and StatusCode is not None else 4)
    )

    def __init__(
        self,
        database: str | None = None,
        timeout: int | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize DatabaseTimeoutError."""
        data = {}
        if timeout:
            data["timeout"] = timeout
        if additional_data:
            data.update(additional_data)
        super().__init__(database=database, lang=lang, additional_data=data or None)

archipy.models.errors.database_errors.DatabaseTimeoutError.code class-attribute

code: str = 'DATABASE_TIMEOUT_ERROR'

archipy.models.errors.database_errors.DatabaseTimeoutError.message_en class-attribute

message_en: str = 'Database operation timed out'

archipy.models.errors.database_errors.DatabaseTimeoutError.message_fa class-attribute

message_fa: str = (
    "عملیات پایگاه داده با تایم\u200cاوت مواجه شد"
)

archipy.models.errors.database_errors.DatabaseTimeoutError.http_status class-attribute

http_status: int = (
    HTTPStatus.REQUEST_TIMEOUT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 408
)

archipy.models.errors.database_errors.DatabaseTimeoutError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.DEADLINE_EXCEEDED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.DEADLINE_EXCEEDED.value, tuple
    )
    else StatusCode.DEADLINE_EXCEEDED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 4
)

archipy.models.errors.database_errors.DatabaseTimeoutError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseTimeoutError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseTimeoutError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseTimeoutError.retryable class-attribute

retryable: bool = False

archipy.models.errors.database_errors.DatabaseTimeoutError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseTimeoutError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseConstraintError

Bases: DatabaseQueryError

Exception raised for database constraint violations.

Source code in archipy/models/errors/database_errors.py
class DatabaseConstraintError(DatabaseQueryError):
    """Exception raised for database constraint violations."""

    code: ClassVar[str] = "DATABASE_CONSTRAINT_ERROR"
    message_en: ClassVar[str] = "Database constraint violation"
    message_fa: ClassVar[str] = "نقض محدودیت پایگاه داده"
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.FAILED_PRECONDITION.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.FAILED_PRECONDITION.value, tuple)
        else (StatusCode.FAILED_PRECONDITION.value if GRPC_AVAILABLE and StatusCode is not None else 9)
    )

    def __init__(
        self,
        database: str | None = None,
        constraint: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize DatabaseConstraintError."""
        data = {}
        if constraint:
            data["constraint"] = constraint
        if additional_data:
            data.update(additional_data)
        super().__init__(database=database, lang=lang, additional_data=data or None)

archipy.models.errors.database_errors.DatabaseConstraintError.code class-attribute

code: str = 'DATABASE_CONSTRAINT_ERROR'

archipy.models.errors.database_errors.DatabaseConstraintError.message_en class-attribute

message_en: str = 'Database constraint violation'

archipy.models.errors.database_errors.DatabaseConstraintError.message_fa class-attribute

message_fa: str = 'نقض محدودیت پایگاه داده'

archipy.models.errors.database_errors.DatabaseConstraintError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.database_errors.DatabaseConstraintError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.FAILED_PRECONDITION.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.FAILED_PRECONDITION.value, tuple
    )
    else StatusCode.FAILED_PRECONDITION.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 9
)

archipy.models.errors.database_errors.DatabaseConstraintError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseConstraintError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseConstraintError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseConstraintError.retryable class-attribute

retryable: bool = False

archipy.models.errors.database_errors.DatabaseConstraintError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseConstraintError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseIntegrityError

Bases: DatabaseQueryError

Exception raised for database integrity violations.

Source code in archipy/models/errors/database_errors.py
class DatabaseIntegrityError(DatabaseQueryError):
    """Exception raised for database integrity violations."""

    code: ClassVar[str] = "DATABASE_INTEGRITY_ERROR"
    message_en: ClassVar[str] = "Database integrity violation"
    message_fa: ClassVar[str] = "نقض یکپارچگی پایگاه داده"
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.FAILED_PRECONDITION.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.FAILED_PRECONDITION.value, tuple)
        else (StatusCode.FAILED_PRECONDITION.value if GRPC_AVAILABLE and StatusCode is not None else 9)
    )

archipy.models.errors.database_errors.DatabaseIntegrityError.code class-attribute

code: str = 'DATABASE_INTEGRITY_ERROR'

archipy.models.errors.database_errors.DatabaseIntegrityError.message_en class-attribute

message_en: str = 'Database integrity violation'

archipy.models.errors.database_errors.DatabaseIntegrityError.message_fa class-attribute

message_fa: str = 'نقض یکپارچگی پایگاه داده'

archipy.models.errors.database_errors.DatabaseIntegrityError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.database_errors.DatabaseIntegrityError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.FAILED_PRECONDITION.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.FAILED_PRECONDITION.value, tuple
    )
    else StatusCode.FAILED_PRECONDITION.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 9
)

archipy.models.errors.database_errors.DatabaseIntegrityError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseIntegrityError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseIntegrityError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseIntegrityError.retryable class-attribute

retryable: bool = False

archipy.models.errors.database_errors.DatabaseIntegrityError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseIntegrityError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseDeadlockError

Bases: DatabaseQueryError

Exception raised for database deadlock errors.

Source code in archipy/models/errors/database_errors.py
class DatabaseDeadlockError(DatabaseQueryError):
    """Exception raised for database deadlock errors."""

    code: ClassVar[str] = "DATABASE_DEADLOCK_ERROR"
    retryable: ClassVar[bool] = True
    message_en: ClassVar[str] = "Database deadlock detected"
    message_fa: ClassVar[str] = "قفل‌شدگی پایگاه داده تشخیص داده شد"
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.ABORTED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.ABORTED.value, tuple)
        else (StatusCode.ABORTED.value if GRPC_AVAILABLE and StatusCode is not None else 10)
    )

archipy.models.errors.database_errors.DatabaseDeadlockError.code class-attribute

code: str = 'DATABASE_DEADLOCK_ERROR'

archipy.models.errors.database_errors.DatabaseDeadlockError.retryable class-attribute

retryable: bool = True

archipy.models.errors.database_errors.DatabaseDeadlockError.message_en class-attribute

message_en: str = 'Database deadlock detected'

archipy.models.errors.database_errors.DatabaseDeadlockError.message_fa class-attribute

message_fa: str = 'قفل\u200cشدگی پایگاه داده تشخیص داده شد'

archipy.models.errors.database_errors.DatabaseDeadlockError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.database_errors.DatabaseDeadlockError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.ABORTED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.ABORTED.value, tuple)
    else StatusCode.ABORTED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 10
)

archipy.models.errors.database_errors.DatabaseDeadlockError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseDeadlockError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseDeadlockError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseDeadlockError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseDeadlockError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseSerializationError

Bases: DatabaseQueryError

Exception raised for database serialization errors.

Source code in archipy/models/errors/database_errors.py
class DatabaseSerializationError(DatabaseQueryError):
    """Exception raised for database serialization errors."""

    code: ClassVar[str] = "DATABASE_SERIALIZATION_ERROR"
    retryable: ClassVar[bool] = True
    message_en: ClassVar[str] = "Database serialization failure"
    message_fa: ClassVar[str] = "خطای سریال‌سازی پایگاه داده"
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.ABORTED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.ABORTED.value, tuple)
        else (StatusCode.ABORTED.value if GRPC_AVAILABLE and StatusCode is not None else 10)
    )

archipy.models.errors.database_errors.DatabaseSerializationError.code class-attribute

code: str = 'DATABASE_SERIALIZATION_ERROR'

archipy.models.errors.database_errors.DatabaseSerializationError.retryable class-attribute

retryable: bool = True

archipy.models.errors.database_errors.DatabaseSerializationError.message_en class-attribute

message_en: str = 'Database serialization failure'

archipy.models.errors.database_errors.DatabaseSerializationError.message_fa class-attribute

message_fa: str = 'خطای سریال\u200cسازی پایگاه داده'

archipy.models.errors.database_errors.DatabaseSerializationError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.database_errors.DatabaseSerializationError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.ABORTED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.ABORTED.value, tuple)
    else StatusCode.ABORTED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 10
)

archipy.models.errors.database_errors.DatabaseSerializationError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseSerializationError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseSerializationError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseSerializationError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseSerializationError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseResourceExhaustedError

Bases: DatabaseQueryError

Exception raised when the database server runs out of a resource such as memory or connections.

The condition is usually transient, so callers may retry with backoff.

Source code in archipy/models/errors/database_errors.py
class DatabaseResourceExhaustedError(DatabaseQueryError):
    """Exception raised when the database server runs out of a resource such as memory or connections.

    The condition is usually transient, so callers may retry with backoff.
    """

    code: ClassVar[str] = "DATABASE_RESOURCE_EXHAUSTED_ERROR"
    retryable: ClassVar[bool] = True
    message_en: ClassVar[str] = "Database resources exhausted"
    message_fa: ClassVar[str] = "منابع پایگاه داده تمام شده است"
    http_status: ClassVar[int] = (
        HTTPStatus.SERVICE_UNAVAILABLE.value if HTTP_AVAILABLE and HTTPStatus is not None else 503
    )
    grpc_status: ClassVar[int] = (
        StatusCode.RESOURCE_EXHAUSTED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.RESOURCE_EXHAUSTED.value, tuple)
        else (StatusCode.RESOURCE_EXHAUSTED.value if GRPC_AVAILABLE and StatusCode is not None else 8)
    )

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.code class-attribute

code: str = 'DATABASE_RESOURCE_EXHAUSTED_ERROR'

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.retryable class-attribute

retryable: bool = True

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.message_en class-attribute

message_en: str = 'Database resources exhausted'

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.message_fa class-attribute

message_fa: str = 'منابع پایگاه داده تمام شده است'

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.http_status class-attribute

http_status: int = (
    HTTPStatus.SERVICE_UNAVAILABLE.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 503
)

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.RESOURCE_EXHAUSTED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.RESOURCE_EXHAUSTED.value, tuple
    )
    else StatusCode.RESOURCE_EXHAUSTED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 8
)

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseResourceExhaustedError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError

Bases: DatabaseQueryError

Exception raised when the database cannot tell whether a statement completed.

The outcome is unknown, so the operation must not be retried blindly unless it is idempotent.

Source code in archipy/models/errors/database_errors.py
class DatabaseUnknownOutcomeError(DatabaseQueryError):
    """Exception raised when the database cannot tell whether a statement completed.

    The outcome is unknown, so the operation must not be retried blindly unless it is idempotent.
    """

    code: ClassVar[str] = "DATABASE_UNKNOWN_OUTCOME_ERROR"
    message_en: ClassVar[str] = "Database statement outcome is unknown"
    message_fa: ClassVar[str] = "نتیجه اجرای دستور پایگاه داده نامشخص است"

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.code class-attribute

code: str = 'DATABASE_UNKNOWN_OUTCOME_ERROR'

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.message_en class-attribute

message_en: str = 'Database statement outcome is unknown'

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.message_fa class-attribute

message_fa: str = "نتیجه اجرای دستور پایگاه داده نامشخص است"

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.retryable class-attribute

retryable: bool = False

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseUnknownOutcomeError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.DatabaseConfigurationError

Bases: DatabaseError

Exception raised for database configuration errors.

Source code in archipy/models/errors/database_errors.py
class DatabaseConfigurationError(DatabaseError):
    """Exception raised for database configuration errors."""

    code: ClassVar[str] = "DATABASE_CONFIGURATION_ERROR"
    message_en: ClassVar[str] = "Database configuration error"
    message_fa: ClassVar[str] = "خطای پیکربندی پایگاه داده"
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

archipy.models.errors.database_errors.DatabaseConfigurationError.code class-attribute

code: str = 'DATABASE_CONFIGURATION_ERROR'

archipy.models.errors.database_errors.DatabaseConfigurationError.message_en class-attribute

message_en: str = 'Database configuration error'

archipy.models.errors.database_errors.DatabaseConfigurationError.message_fa class-attribute

message_fa: str = 'خطای پیکربندی پایگاه داده'

archipy.models.errors.database_errors.DatabaseConfigurationError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.database_errors.DatabaseConfigurationError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.database_errors.DatabaseConfigurationError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.DatabaseConfigurationError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.DatabaseConfigurationError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.DatabaseConfigurationError.retryable class-attribute

retryable: bool = False

archipy.models.errors.database_errors.DatabaseConfigurationError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.DatabaseConfigurationError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.CacheError

Bases: BaseError

Exception raised for cache access errors.

Source code in archipy/models/errors/database_errors.py
class CacheError(BaseError):
    """Exception raised for cache access errors."""

    code: ClassVar[str] = "CACHE_ERROR"
    message_en: ClassVar[str] = "Error accessing cache"
    message_fa: ClassVar[str] = "خطا در دسترسی به حافظه نهان"
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

    def __init__(
        self,
        cache_type: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize CacheError."""
        data = {}
        if cache_type:
            data["cache_type"] = cache_type
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.database_errors.CacheError.code class-attribute

code: str = 'CACHE_ERROR'

archipy.models.errors.database_errors.CacheError.message_en class-attribute

message_en: str = 'Error accessing cache'

archipy.models.errors.database_errors.CacheError.message_fa class-attribute

message_fa: str = 'خطا در دسترسی به حافظه نهان'

archipy.models.errors.database_errors.CacheError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.database_errors.CacheError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.database_errors.CacheError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.CacheError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.CacheError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.CacheError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.database_errors.CacheError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.database_errors.CacheMissError

Bases: BaseError

Exception raised when requested data is not found in cache.

Source code in archipy/models/errors/database_errors.py
class CacheMissError(BaseError):
    """Exception raised when requested data is not found in cache."""

    code: ClassVar[str] = "CACHE_MISS"
    message_en: ClassVar[str] = "Requested data not found in cache: {cache_key}"
    message_fa: ClassVar[str] = "داده درخواستی در حافظه نهان یافت نشد: {cache_key}"
    http_status: ClassVar[int] = HTTPStatus.NOT_FOUND.value if HTTP_AVAILABLE and HTTPStatus is not None else 404
    grpc_status: ClassVar[int] = (
        StatusCode.NOT_FOUND.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.NOT_FOUND.value, tuple)
        else (StatusCode.NOT_FOUND.value if GRPC_AVAILABLE and StatusCode is not None else 5)
    )

    def __init__(
        self,
        cache_key: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize CacheMissError."""
        data = {"cache_key": cache_key} if cache_key else {}
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

    def get_message(self) -> str:
        """Gets the localized error message with cache key."""
        template = self.message_fa if self.lang == LanguageType.FA else self.message_en
        cache_key = self.additional_data.get("cache_key", "cache_key")
        return template.format(cache_key=cache_key)

archipy.models.errors.database_errors.CacheMissError.code class-attribute

code: str = 'CACHE_MISS'

archipy.models.errors.database_errors.CacheMissError.message_en class-attribute

message_en: str = (
    "Requested data not found in cache: {cache_key}"
)

archipy.models.errors.database_errors.CacheMissError.message_fa class-attribute

message_fa: str = (
    "داده درخواستی در حافظه نهان یافت نشد: {cache_key}"
)

archipy.models.errors.database_errors.CacheMissError.http_status class-attribute

http_status: int = (
    HTTPStatus.NOT_FOUND.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 404
)

archipy.models.errors.database_errors.CacheMissError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.NOT_FOUND.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.NOT_FOUND.value, tuple)
    else StatusCode.NOT_FOUND.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 5
)

archipy.models.errors.database_errors.CacheMissError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.database_errors.CacheMissError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.database_errors.CacheMissError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.database_errors.CacheMissError.get_message

get_message() -> str

Gets the localized error message with cache key.

Source code in archipy/models/errors/database_errors.py
def get_message(self) -> str:
    """Gets the localized error message with cache key."""
    template = self.message_fa if self.lang == LanguageType.FA else self.message_en
    cache_key = self.additional_data.get("cache_key", "cache_key")
    return template.format(cache_key=cache_key)

archipy.models.errors.database_errors.CacheMissError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

options: show_root_toc_entry: false heading_level: 3

System Errors

Exceptions for system-level failures including configuration errors and unexpected runtime conditions.

System-level error types.

archipy.models.errors.system_errors.HTTP_AVAILABLE module-attribute

HTTP_AVAILABLE = True

archipy.models.errors.system_errors.GRPC_AVAILABLE module-attribute

GRPC_AVAILABLE = True

archipy.models.errors.system_errors.InternalError

Bases: BaseError

Represents an internal server error.

This error is typically used when an unexpected condition is encountered that prevents the server from fulfilling the request.

Source code in archipy/models/errors/system_errors.py
class InternalError(BaseError):
    """Represents an internal server error.

    This error is typically used when an unexpected condition is encountered
    that prevents the server from fulfilling the request.
    """

    code: ClassVar[str] = "INTERNAL_ERROR"
    message_en: ClassVar[str] = "Internal system error occurred"
    message_fa: ClassVar[str] = "خطای داخلی سیستم رخ داده است."
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

    def __init__(
        self,
        error_code: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize InternalError."""
        data = {}
        if error_code:
            data["error_code"] = error_code
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.system_errors.InternalError.code class-attribute

code: str = 'INTERNAL_ERROR'

archipy.models.errors.system_errors.InternalError.message_en class-attribute

message_en: str = 'Internal system error occurred'

archipy.models.errors.system_errors.InternalError.message_fa class-attribute

message_fa: str = 'خطای داخلی سیستم رخ داده است.'

archipy.models.errors.system_errors.InternalError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.system_errors.InternalError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.system_errors.InternalError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.system_errors.InternalError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.system_errors.InternalError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.system_errors.InternalError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.system_errors.InternalError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.system_errors.ConfigurationError

Bases: BaseError

Represents a configuration error.

This error is used when there is a problem with the application's configuration that prevents it from operating correctly.

Source code in archipy/models/errors/system_errors.py
class ConfigurationError(BaseError):
    """Represents a configuration error.

    This error is used when there is a problem with the application's
    configuration that prevents it from operating correctly.
    """

    code: ClassVar[str] = "CONFIGURATION_ERROR"
    message_en: ClassVar[str] = "Error in system configuration"
    message_fa: ClassVar[str] = "خطا در پیکربندی سیستم"
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

    def __init__(
        self,
        operation: str | None = None,
        reason: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize ConfigurationError."""
        data = {}
        if operation:
            data["operation"] = operation
        if reason:
            data["reason"] = reason
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.system_errors.ConfigurationError.code class-attribute

code: str = 'CONFIGURATION_ERROR'

archipy.models.errors.system_errors.ConfigurationError.message_en class-attribute

message_en: str = 'Error in system configuration'

archipy.models.errors.system_errors.ConfigurationError.message_fa class-attribute

message_fa: str = 'خطا در پیکربندی سیستم'

archipy.models.errors.system_errors.ConfigurationError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.system_errors.ConfigurationError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.system_errors.ConfigurationError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.system_errors.ConfigurationError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.system_errors.ConfigurationError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.system_errors.ConfigurationError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.system_errors.ConfigurationError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.system_errors.UnavailableError

Bases: BaseError

Represents a resource unavailability error.

This error is used when a required resource is temporarily unavailable but may become available again in the future.

Source code in archipy/models/errors/system_errors.py
class UnavailableError(BaseError):
    """Represents a resource unavailability error.

    This error is used when a required resource is temporarily unavailable
    but may become available again in the future.
    """

    code: ClassVar[str] = "UNAVAILABLE"
    message_en: ClassVar[str] = "Service is currently unavailable"
    message_fa: ClassVar[str] = "سرویس در حال حاضر در دسترس نیست."
    http_status: ClassVar[int] = (
        HTTPStatus.SERVICE_UNAVAILABLE.value if HTTP_AVAILABLE and HTTPStatus is not None else 503
    )
    grpc_status: ClassVar[int] = (
        StatusCode.UNAVAILABLE.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAVAILABLE.value, tuple)
        else (StatusCode.UNAVAILABLE.value if GRPC_AVAILABLE and StatusCode is not None else 14)
    )

    def __init__(
        self,
        resource_type: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize UnavailableError."""
        data = {}
        if resource_type:
            data["resource_type"] = resource_type
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.system_errors.UnavailableError.code class-attribute

code: str = 'UNAVAILABLE'

archipy.models.errors.system_errors.UnavailableError.message_en class-attribute

message_en: str = 'Service is currently unavailable'

archipy.models.errors.system_errors.UnavailableError.message_fa class-attribute

message_fa: str = 'سرویس در حال حاضر در دسترس نیست.'

archipy.models.errors.system_errors.UnavailableError.http_status class-attribute

http_status: int = (
    HTTPStatus.SERVICE_UNAVAILABLE.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 503
)

archipy.models.errors.system_errors.UnavailableError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAVAILABLE.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAVAILABLE.value, tuple)
    else StatusCode.UNAVAILABLE.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 14
)

archipy.models.errors.system_errors.UnavailableError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.system_errors.UnavailableError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.system_errors.UnavailableError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.system_errors.UnavailableError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.system_errors.UnavailableError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.system_errors.UnknownError

Bases: BaseError

Represents an unknown error.

This is a catch-all error type for unexpected conditions that don't fit into other error categories.

Source code in archipy/models/errors/system_errors.py
class UnknownError(BaseError):
    """Represents an unknown error.

    This is a catch-all error type for unexpected conditions that
    don't fit into other error categories.
    """

    code: ClassVar[str] = "UNKNOWN_ERROR"
    message_en: ClassVar[str] = "An unknown error occurred"
    message_fa: ClassVar[str] = "خطای ناشناخته‌ای رخ داده است."
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.UNKNOWN.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNKNOWN.value, tuple)
        else (StatusCode.UNKNOWN.value if GRPC_AVAILABLE and StatusCode is not None else 2)
    )

    def __init__(
        self,
        config_key: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize UnknownError."""
        data = {}
        if config_key:
            data["config_key"] = config_key
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.system_errors.UnknownError.code class-attribute

code: str = 'UNKNOWN_ERROR'

archipy.models.errors.system_errors.UnknownError.message_en class-attribute

message_en: str = 'An unknown error occurred'

archipy.models.errors.system_errors.UnknownError.message_fa class-attribute

message_fa: str = 'خطای ناشناخته\u200cای رخ داده است.'

archipy.models.errors.system_errors.UnknownError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.system_errors.UnknownError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNKNOWN.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNKNOWN.value, tuple)
    else StatusCode.UNKNOWN.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 2
)

archipy.models.errors.system_errors.UnknownError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.system_errors.UnknownError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.system_errors.UnknownError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.system_errors.UnknownError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.system_errors.UnknownError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.system_errors.AbortedError

Bases: BaseError

Represents an aborted operation error.

This error is used when an operation is aborted, typically due to a concurrency issue or user cancellation.

Source code in archipy/models/errors/system_errors.py
class AbortedError(BaseError):
    """Represents an aborted operation error.

    This error is used when an operation is aborted, typically due to
    a concurrency issue or user cancellation.
    """

    code: ClassVar[str] = "ABORTED"
    message_en: ClassVar[str] = "Operation was aborted"
    message_fa: ClassVar[str] = "عملیات متوقف شد."
    http_status: ClassVar[int] = HTTPStatus.CONFLICT.value if HTTP_AVAILABLE and HTTPStatus is not None else 409
    grpc_status: ClassVar[int] = (
        StatusCode.ABORTED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.ABORTED.value, tuple)
        else (StatusCode.ABORTED.value if GRPC_AVAILABLE and StatusCode is not None else 10)
    )

    def __init__(
        self,
        service: str | None = None,
        reason: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize AbortedError."""
        data = {}
        if service:
            data["service"] = service
        if reason:
            data["reason"] = reason
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.system_errors.AbortedError.code class-attribute

code: str = 'ABORTED'

archipy.models.errors.system_errors.AbortedError.message_en class-attribute

message_en: str = 'Operation was aborted'

archipy.models.errors.system_errors.AbortedError.message_fa class-attribute

message_fa: str = 'عملیات متوقف شد.'

archipy.models.errors.system_errors.AbortedError.http_status class-attribute

http_status: int = (
    HTTPStatus.CONFLICT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 409
)

archipy.models.errors.system_errors.AbortedError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.ABORTED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.ABORTED.value, tuple)
    else StatusCode.ABORTED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 10
)

archipy.models.errors.system_errors.AbortedError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.system_errors.AbortedError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.system_errors.AbortedError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.system_errors.AbortedError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.system_errors.AbortedError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.system_errors.DeadlockDetectedError

Bases: BaseError

Represents a deadlock detection error.

This error is used when a deadlock is detected in a system operation, typically in database transactions or resource locking scenarios.

Source code in archipy/models/errors/system_errors.py
class DeadlockDetectedError(BaseError):
    """Represents a deadlock detection error.

    This error is used when a deadlock is detected in a system operation,
    typically in database transactions or resource locking scenarios.
    """

    code: ClassVar[str] = "DEADLOCK"
    message_en: ClassVar[str] = "Deadlock detected"
    message_fa: ClassVar[str] = "خطای قفل‌شدگی (Deadlock) تشخیص داده شد."
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

    def __init__(
        self,
        service: str | None = None,
        reason: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize DeadlockDetectedError."""
        data = {}
        if service:
            data["service"] = service
        if reason:
            data["reason"] = reason
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.system_errors.DeadlockDetectedError.code class-attribute

code: str = 'DEADLOCK'

archipy.models.errors.system_errors.DeadlockDetectedError.message_en class-attribute

message_en: str = 'Deadlock detected'

archipy.models.errors.system_errors.DeadlockDetectedError.message_fa class-attribute

message_fa: str = (
    "خطای قفل\u200cشدگی (Deadlock) تشخیص داده شد."
)

archipy.models.errors.system_errors.DeadlockDetectedError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.system_errors.DeadlockDetectedError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.system_errors.DeadlockDetectedError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.system_errors.DeadlockDetectedError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.system_errors.DeadlockDetectedError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.system_errors.DeadlockDetectedError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.system_errors.DeadlockDetectedError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.system_errors.DeadlineExceededError

Bases: BaseError

Raised when an operation exceeds its deadline/timeout.

This error is typically used in decorators or functions that have time limits or deadlines for completion.

Source code in archipy/models/errors/system_errors.py
class DeadlineExceededError(BaseError):
    """Raised when an operation exceeds its deadline/timeout.

    This error is typically used in decorators or functions that have
    time limits or deadlines for completion.
    """

    code: ClassVar[str] = "DEADLINE_EXCEEDED"
    message_en: ClassVar[str] = "Operation exceeded its deadline"
    message_fa: ClassVar[str] = "عملیات از مهلت زمانی مجاز تجاوز کرد"
    http_status: ClassVar[int] = HTTPStatus.REQUEST_TIMEOUT.value if HTTP_AVAILABLE and HTTPStatus is not None else 408
    grpc_status: ClassVar[int] = (
        StatusCode.DEADLINE_EXCEEDED.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.DEADLINE_EXCEEDED.value, tuple)
        else (StatusCode.DEADLINE_EXCEEDED.value if GRPC_AVAILABLE and StatusCode is not None else 4)
    )

    def __init__(
        self,
        timeout: float | None = None,
        operation: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize DeadlineExceededError.

        Args:
            timeout: The timeout value that was exceeded (in seconds).
            operation: The operation that exceeded the deadline.
            lang: The language for error messages.
            additional_data: Additional context data.
        """
        data = {}
        if timeout is not None:
            data["timeout"] = timeout
        if operation:
            data["operation"] = operation
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.system_errors.DeadlineExceededError.code class-attribute

code: str = 'DEADLINE_EXCEEDED'

archipy.models.errors.system_errors.DeadlineExceededError.message_en class-attribute

message_en: str = 'Operation exceeded its deadline'

archipy.models.errors.system_errors.DeadlineExceededError.message_fa class-attribute

message_fa: str = 'عملیات از مهلت زمانی مجاز تجاوز کرد'

archipy.models.errors.system_errors.DeadlineExceededError.http_status class-attribute

http_status: int = (
    HTTPStatus.REQUEST_TIMEOUT.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 408
)

archipy.models.errors.system_errors.DeadlineExceededError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.DEADLINE_EXCEEDED.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(
        StatusCode.DEADLINE_EXCEEDED.value, tuple
    )
    else StatusCode.DEADLINE_EXCEEDED.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 4
)

archipy.models.errors.system_errors.DeadlineExceededError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.system_errors.DeadlineExceededError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.system_errors.DeadlineExceededError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.system_errors.DeadlineExceededError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.system_errors.DeadlineExceededError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.system_errors.DeprecationError

Bases: BaseError

Raised when deprecated functionality is used.

This error is used to signal that a feature, method, or API is deprecated and should no longer be used.

Source code in archipy/models/errors/system_errors.py
class DeprecationError(BaseError):
    """Raised when deprecated functionality is used.

    This error is used to signal that a feature, method, or API
    is deprecated and should no longer be used.
    """

    code: ClassVar[str] = "DEPRECATED_FEATURE"
    message_en: ClassVar[str] = "This feature is deprecated and should no longer be used"
    message_fa: ClassVar[str] = "این ویژگی منسوخ شده و دیگر نباید استفاده شود"
    http_status: ClassVar[int] = HTTPStatus.GONE.value if HTTP_AVAILABLE and HTTPStatus is not None else 410
    grpc_status: ClassVar[int] = (
        StatusCode.UNAVAILABLE.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAVAILABLE.value, tuple)
        else (StatusCode.UNAVAILABLE.value if GRPC_AVAILABLE and StatusCode is not None else 14)
    )

    def __init__(
        self,
        deprecated_feature: str | None = None,
        replacement: str | None = None,
        removal_version: str | None = None,
        lang: LanguageType | None = None,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize DeprecationError.

        Args:
            deprecated_feature: The name of the deprecated feature.
            replacement: The recommended replacement feature.
            removal_version: The version when the feature will be removed.
            lang: The language for error messages.
            additional_data: Additional context data.
        """
        data = {}
        if deprecated_feature:
            data["deprecated_feature"] = deprecated_feature
        if replacement:
            data["replacement"] = replacement
        if removal_version:
            data["removal_version"] = removal_version
        if additional_data:
            data.update(additional_data)
        super().__init__(lang=lang, additional_data=data or None)

archipy.models.errors.system_errors.DeprecationError.code class-attribute

code: str = 'DEPRECATED_FEATURE'

archipy.models.errors.system_errors.DeprecationError.message_en class-attribute

message_en: str = "This feature is deprecated and should no longer be used"

archipy.models.errors.system_errors.DeprecationError.message_fa class-attribute

message_fa: str = (
    "این ویژگی منسوخ شده و دیگر نباید استفاده شود"
)

archipy.models.errors.system_errors.DeprecationError.http_status class-attribute

http_status: int = (
    HTTPStatus.GONE.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 410
)

archipy.models.errors.system_errors.DeprecationError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAVAILABLE.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAVAILABLE.value, tuple)
    else StatusCode.UNAVAILABLE.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 14
)

archipy.models.errors.system_errors.DeprecationError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.system_errors.DeprecationError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.system_errors.DeprecationError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.system_errors.DeprecationError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.system_errors.DeprecationError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

options: show_root_toc_entry: false heading_level: 3

Keycloak Errors

Exceptions specific to Keycloak integration failures, such as token validation errors and realm configuration issues.

Keycloak-related error types.

archipy.models.errors.keycloak_errors.HTTP_BAD_REQUEST module-attribute

HTTP_BAD_REQUEST = 400

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError

Bases: BaseError

Exception raised when trying to create a realm that already exists.

Source code in archipy/models/errors/keycloak_errors.py
class RealmAlreadyExistsError(BaseError):
    """Exception raised when trying to create a realm that already exists."""

    code: ClassVar[str] = "REALM_ALREADY_EXISTS"
    message_en: ClassVar[str] = "Realm already exists"
    message_fa: ClassVar[str] = "قلمرو از قبل وجود دارد"
    http_status: ClassVar[int] = 409
    grpc_status: ClassVar[int] = 6

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError.code class-attribute

code: str = 'REALM_ALREADY_EXISTS'

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError.message_en class-attribute

message_en: str = 'Realm already exists'

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError.message_fa class-attribute

message_fa: str = 'قلمرو از قبل وجود دارد'

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError.http_status class-attribute

http_status: int = 409

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError.grpc_status class-attribute

grpc_status: int = 6

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.RealmAlreadyExistsError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.UserAlreadyExistsError

Bases: BaseError

Exception raised when trying to create a user that already exists.

Source code in archipy/models/errors/keycloak_errors.py
class UserAlreadyExistsError(BaseError):
    """Exception raised when trying to create a user that already exists."""

    code: ClassVar[str] = "USER_ALREADY_EXISTS"
    message_en: ClassVar[str] = "User already exists"
    message_fa: ClassVar[str] = "کاربر از قبل وجود دارد"
    http_status: ClassVar[int] = 409
    grpc_status: ClassVar[int] = 6

archipy.models.errors.keycloak_errors.UserAlreadyExistsError.code class-attribute

code: str = 'USER_ALREADY_EXISTS'

archipy.models.errors.keycloak_errors.UserAlreadyExistsError.message_en class-attribute

message_en: str = 'User already exists'

archipy.models.errors.keycloak_errors.UserAlreadyExistsError.message_fa class-attribute

message_fa: str = 'کاربر از قبل وجود دارد'

archipy.models.errors.keycloak_errors.UserAlreadyExistsError.http_status class-attribute

http_status: int = 409

archipy.models.errors.keycloak_errors.UserAlreadyExistsError.grpc_status class-attribute

grpc_status: int = 6

archipy.models.errors.keycloak_errors.UserAlreadyExistsError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.UserAlreadyExistsError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.UserAlreadyExistsError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.UserAlreadyExistsError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.UserAlreadyExistsError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError

Bases: BaseError

Exception raised when trying to create a client that already exists.

Source code in archipy/models/errors/keycloak_errors.py
class ClientAlreadyExistsError(BaseError):
    """Exception raised when trying to create a client that already exists."""

    code: ClassVar[str] = "CLIENT_ALREADY_EXISTS"
    message_en: ClassVar[str] = "Client already exists"
    message_fa: ClassVar[str] = "کلاینت از قبل وجود دارد"
    http_status: ClassVar[int] = 409
    grpc_status: ClassVar[int] = 6

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError.code class-attribute

code: str = 'CLIENT_ALREADY_EXISTS'

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError.message_en class-attribute

message_en: str = 'Client already exists'

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError.message_fa class-attribute

message_fa: str = 'کلاینت از قبل وجود دارد'

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError.http_status class-attribute

http_status: int = 409

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError.grpc_status class-attribute

grpc_status: int = 6

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.ClientAlreadyExistsError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError

Bases: BaseError

Exception raised when trying to create a role that already exists.

Source code in archipy/models/errors/keycloak_errors.py
class RoleAlreadyExistsError(BaseError):
    """Exception raised when trying to create a role that already exists."""

    code: ClassVar[str] = "ROLE_ALREADY_EXISTS"
    message_en: ClassVar[str] = "Role already exists"
    message_fa: ClassVar[str] = "نقش از قبل وجود دارد"
    http_status: ClassVar[int] = 409
    grpc_status: ClassVar[int] = 6

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError.code class-attribute

code: str = 'ROLE_ALREADY_EXISTS'

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError.message_en class-attribute

message_en: str = 'Role already exists'

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError.message_fa class-attribute

message_fa: str = 'نقش از قبل وجود دارد'

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError.http_status class-attribute

http_status: int = 409

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError.grpc_status class-attribute

grpc_status: int = 6

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.RoleAlreadyExistsError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.InvalidCredentialsError

Bases: BaseError

Exception raised for invalid authentication credentials.

Source code in archipy/models/errors/keycloak_errors.py
class InvalidCredentialsError(BaseError):
    """Exception raised for invalid authentication credentials."""

    code: ClassVar[str] = "INVALID_CREDENTIALS"
    message_en: ClassVar[str] = "Invalid credentials"
    message_fa: ClassVar[str] = "اطلاعات ورود نامعتبر"
    http_status: ClassVar[int] = 401
    grpc_status: ClassVar[int] = 16

archipy.models.errors.keycloak_errors.InvalidCredentialsError.code class-attribute

code: str = 'INVALID_CREDENTIALS'

archipy.models.errors.keycloak_errors.InvalidCredentialsError.message_en class-attribute

message_en: str = 'Invalid credentials'

archipy.models.errors.keycloak_errors.InvalidCredentialsError.message_fa class-attribute

message_fa: str = 'اطلاعات ورود نامعتبر'

archipy.models.errors.keycloak_errors.InvalidCredentialsError.http_status class-attribute

http_status: int = 401

archipy.models.errors.keycloak_errors.InvalidCredentialsError.grpc_status class-attribute

grpc_status: int = 16

archipy.models.errors.keycloak_errors.InvalidCredentialsError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.InvalidCredentialsError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.InvalidCredentialsError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.InvalidCredentialsError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.InvalidCredentialsError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.ResourceNotFoundError

Bases: BaseError

Exception raised when a resource is not found.

Source code in archipy/models/errors/keycloak_errors.py
class ResourceNotFoundError(BaseError):
    """Exception raised when a resource is not found."""

    code: ClassVar[str] = "RESOURCE_NOT_FOUND"
    message_en: ClassVar[str] = "Resource not found"
    message_fa: ClassVar[str] = "منبع یافت نشد"
    http_status: ClassVar[int] = 404
    grpc_status: ClassVar[int] = 5

archipy.models.errors.keycloak_errors.ResourceNotFoundError.code class-attribute

code: str = 'RESOURCE_NOT_FOUND'

archipy.models.errors.keycloak_errors.ResourceNotFoundError.message_en class-attribute

message_en: str = 'Resource not found'

archipy.models.errors.keycloak_errors.ResourceNotFoundError.message_fa class-attribute

message_fa: str = 'منبع یافت نشد'

archipy.models.errors.keycloak_errors.ResourceNotFoundError.http_status class-attribute

http_status: int = 404

archipy.models.errors.keycloak_errors.ResourceNotFoundError.grpc_status class-attribute

grpc_status: int = 5

archipy.models.errors.keycloak_errors.ResourceNotFoundError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.ResourceNotFoundError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.ResourceNotFoundError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.ResourceNotFoundError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.ResourceNotFoundError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.InsufficientPermissionsError

Bases: BaseError

Exception raised when user lacks required permissions.

Source code in archipy/models/errors/keycloak_errors.py
class InsufficientPermissionsError(BaseError):
    """Exception raised when user lacks required permissions."""

    code: ClassVar[str] = "INSUFFICIENT_PERMISSIONS"
    message_en: ClassVar[str] = "Insufficient permissions"
    message_fa: ClassVar[str] = "دسترسی کافی نیست"
    http_status: ClassVar[int] = 403
    grpc_status: ClassVar[int] = 7

archipy.models.errors.keycloak_errors.InsufficientPermissionsError.code class-attribute

code: str = 'INSUFFICIENT_PERMISSIONS'

archipy.models.errors.keycloak_errors.InsufficientPermissionsError.message_en class-attribute

message_en: str = 'Insufficient permissions'

archipy.models.errors.keycloak_errors.InsufficientPermissionsError.message_fa class-attribute

message_fa: str = 'دسترسی کافی نیست'

archipy.models.errors.keycloak_errors.InsufficientPermissionsError.http_status class-attribute

http_status: int = 403

archipy.models.errors.keycloak_errors.InsufficientPermissionsError.grpc_status class-attribute

grpc_status: int = 7

archipy.models.errors.keycloak_errors.InsufficientPermissionsError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.InsufficientPermissionsError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.InsufficientPermissionsError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.InsufficientPermissionsError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.InsufficientPermissionsError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.ValidationError

Bases: BaseError

Exception raised for validation errors.

Source code in archipy/models/errors/keycloak_errors.py
class ValidationError(BaseError):
    """Exception raised for validation errors."""

    code: ClassVar[str] = "VALIDATION_ERROR"
    message_en: ClassVar[str] = "Validation error"
    message_fa: ClassVar[str] = "خطای اعتبارسنجی"
    http_status: ClassVar[int] = 400
    grpc_status: ClassVar[int] = 3

archipy.models.errors.keycloak_errors.ValidationError.code class-attribute

code: str = 'VALIDATION_ERROR'

archipy.models.errors.keycloak_errors.ValidationError.message_en class-attribute

message_en: str = 'Validation error'

archipy.models.errors.keycloak_errors.ValidationError.message_fa class-attribute

message_fa: str = 'خطای اعتبارسنجی'

archipy.models.errors.keycloak_errors.ValidationError.http_status class-attribute

http_status: int = 400

archipy.models.errors.keycloak_errors.ValidationError.grpc_status class-attribute

grpc_status: int = 3

archipy.models.errors.keycloak_errors.ValidationError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.ValidationError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.ValidationError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.ValidationError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.ValidationError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.PasswordPolicyError

Bases: BaseError

Exception raised when password doesn't meet policy requirements.

Source code in archipy/models/errors/keycloak_errors.py
class PasswordPolicyError(BaseError):
    """Exception raised when password doesn't meet policy requirements."""

    code: ClassVar[str] = "PASSWORD_POLICY_VIOLATION"
    message_en: ClassVar[str] = "Password does not meet policy requirements"
    message_fa: ClassVar[str] = "رمز عبور الزامات سیاست را برآورده نمی‌کند"
    http_status: ClassVar[int] = 400
    grpc_status: ClassVar[int] = 3

archipy.models.errors.keycloak_errors.PasswordPolicyError.code class-attribute

code: str = 'PASSWORD_POLICY_VIOLATION'

archipy.models.errors.keycloak_errors.PasswordPolicyError.message_en class-attribute

message_en: str = (
    "Password does not meet policy requirements"
)

archipy.models.errors.keycloak_errors.PasswordPolicyError.message_fa class-attribute

message_fa: str = (
    "رمز عبور الزامات سیاست را برآورده نمی\u200cکند"
)

archipy.models.errors.keycloak_errors.PasswordPolicyError.http_status class-attribute

http_status: int = 400

archipy.models.errors.keycloak_errors.PasswordPolicyError.grpc_status class-attribute

grpc_status: int = 3

archipy.models.errors.keycloak_errors.PasswordPolicyError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.PasswordPolicyError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.PasswordPolicyError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.PasswordPolicyError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.PasswordPolicyError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError

Bases: BaseError

Exception raised when Keycloak connection times out.

Source code in archipy/models/errors/keycloak_errors.py
class KeycloakConnectionTimeoutError(BaseError):
    """Exception raised when Keycloak connection times out."""

    code: ClassVar[str] = "CONNECTION_TIMEOUT"
    message_en: ClassVar[str] = "Connection timeout"
    message_fa: ClassVar[str] = "زمان اتصال به پایان رسید"
    http_status: ClassVar[int] = 504
    grpc_status: ClassVar[int] = 4

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError.code class-attribute

code: str = 'CONNECTION_TIMEOUT'

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError.message_en class-attribute

message_en: str = 'Connection timeout'

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError.message_fa class-attribute

message_fa: str = 'زمان اتصال به پایان رسید'

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError.http_status class-attribute

http_status: int = 504

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError.grpc_status class-attribute

grpc_status: int = 4

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.KeycloakConnectionTimeoutError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError

Bases: BaseError

Exception raised when Keycloak service is unavailable.

Source code in archipy/models/errors/keycloak_errors.py
class KeycloakServiceUnavailableError(BaseError):
    """Exception raised when Keycloak service is unavailable."""

    code: ClassVar[str] = "SERVICE_UNAVAILABLE"
    message_en: ClassVar[str] = "Service unavailable"
    message_fa: ClassVar[str] = "سرویس در دسترس نیست"
    http_status: ClassVar[int] = 503
    grpc_status: ClassVar[int] = 14

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError.code class-attribute

code: str = 'SERVICE_UNAVAILABLE'

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError.message_en class-attribute

message_en: str = 'Service unavailable'

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError.message_fa class-attribute

message_fa: str = 'سرویس در دسترس نیست'

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError.http_status class-attribute

http_status: int = 503

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError.grpc_status class-attribute

grpc_status: int = 14

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.keycloak_errors.KeycloakServiceUnavailableError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.keycloak_errors.get_error_message

get_error_message(keycloak_error: KeycloakError) -> str

Extract the actual error message from Keycloak error.

Source code in archipy/models/errors/keycloak_errors.py
def get_error_message(keycloak_error: KeycloakError) -> str:
    """Extract the actual error message from Keycloak error."""
    error_message = str(keycloak_error)

    # Try to parse JSON response body
    if hasattr(keycloak_error, "response_body") and keycloak_error.response_body:
        try:
            body = keycloak_error.response_body
            body_str = body.decode("utf-8") if isinstance(body, bytes) else str(body)

            # body_str is now guaranteed to be str after decode
            parsed = json.loads(body_str)
            if isinstance(parsed, dict):
                error_message = (
                    parsed.get("errorMessage")
                    or parsed.get("error_description")
                    or parsed.get("error")
                    or error_message
                )
        except json.JSONDecodeError, UnicodeDecodeError:
            pass

    return error_message

archipy.models.errors.keycloak_errors.handle_keycloak_error

handle_keycloak_error(
    keycloak_error: KeycloakError, **additional_data: object
) -> BaseError

Convert Keycloak error to appropriate custom error.

Source code in archipy/models/errors/keycloak_errors.py
def handle_keycloak_error(keycloak_error: KeycloakError, **additional_data: object) -> BaseError:
    """Convert Keycloak error to appropriate custom error."""
    error_message = get_error_message(keycloak_error)
    response_code = getattr(keycloak_error, "response_code", None)

    # Add context data
    context = {
        "original_error": error_message,
        "response_code": response_code,
        "keycloak_error_type": type(keycloak_error).__name__,
        **additional_data,
    }

    # Simple string matching to identify error types
    error_lower = error_message.lower()

    # Realm errors
    if "realm" in error_lower and "already exists" in error_lower:
        return RealmAlreadyExistsError(additional_data=context)

    # User errors
    if "user exists with same" in error_lower:
        return UserAlreadyExistsError(additional_data=context)

    # Client errors
    if "client" in error_lower and "already exists" in error_lower:
        return ClientAlreadyExistsError(additional_data=context)

    # Authentication errors
    if any(
        phrase in error_lower for phrase in ["invalid user credentials", "invalid credentials", "authentication failed"]
    ):
        return InvalidCredentialsError(additional_data=context)

    # Not found errors
    if "not found" in error_lower:
        return ResourceNotFoundError(additional_data=context)

    # Permission errors
    if any(phrase in error_lower for phrase in ["forbidden", "access denied", "insufficient permissions"]):
        return InsufficientPermissionsError(additional_data=context)

    # Validation errors (400 status codes that don't match above)
    if response_code == HTTP_BAD_REQUEST:
        return ValidationError(additional_data=context)

    # Default to InternalError for unrecognized errors
    return InternalError(additional_data=context)

options: show_root_toc_entry: false heading_level: 3

Temporal Errors

Exceptions specific to Temporal workflow orchestration failures, such as workflow execution errors and activity timeouts.

Temporal-specific error definitions.

This module defines custom exception classes for Temporal worker operations, extending the base ArchiPy error handling patterns.

archipy.models.errors.temporal_errors.HTTP_AVAILABLE module-attribute

HTTP_AVAILABLE = True

archipy.models.errors.temporal_errors.GRPC_AVAILABLE module-attribute

GRPC_AVAILABLE = True

archipy.models.errors.temporal_errors.TemporalError

Bases: BaseError

Base exception for all Temporal-related errors.

This is the root exception class for all Temporal workflow engine errors within the ArchiPy system.

Source code in archipy/models/errors/temporal_errors.py
class TemporalError(BaseError):
    """Base exception for all Temporal-related errors.

    This is the root exception class for all Temporal workflow engine errors
    within the ArchiPy system.
    """

    code: ClassVar[str] = "TEMPORAL_ERROR"
    message_en: ClassVar[str] = "Temporal error occurred"
    message_fa: ClassVar[str] = "خطای Temporal رخ داده است"
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

archipy.models.errors.temporal_errors.TemporalError.code class-attribute

code: str = 'TEMPORAL_ERROR'

archipy.models.errors.temporal_errors.TemporalError.message_en class-attribute

message_en: str = 'Temporal error occurred'

archipy.models.errors.temporal_errors.TemporalError.message_fa class-attribute

message_fa: str = 'خطای Temporal رخ داده است'

archipy.models.errors.temporal_errors.TemporalError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.temporal_errors.TemporalError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.temporal_errors.TemporalError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.temporal_errors.TemporalError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.temporal_errors.TemporalError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.temporal_errors.TemporalError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.temporal_errors.TemporalError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.temporal_errors.WorkerConnectionError

Bases: TemporalError

Exception raised when a worker fails to connect to Temporal server.

Source code in archipy/models/errors/temporal_errors.py
class WorkerConnectionError(TemporalError):
    """Exception raised when a worker fails to connect to Temporal server."""

    code: ClassVar[str] = "WORKER_CONNECTION_ERROR"
    message_en: ClassVar[str] = "Failed to connect to Temporal server"
    message_fa: ClassVar[str] = "خطا در اتصال به سرور Temporal"
    http_status: ClassVar[int] = (
        HTTPStatus.SERVICE_UNAVAILABLE.value if HTTP_AVAILABLE and HTTPStatus is not None else 503
    )
    grpc_status: ClassVar[int] = (
        StatusCode.UNAVAILABLE.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.UNAVAILABLE.value, tuple)
        else (StatusCode.UNAVAILABLE.value if GRPC_AVAILABLE and StatusCode is not None else 14)
    )

    def __init__(
        self,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize the worker connection error."""
        super().__init__(additional_data=additional_data)

archipy.models.errors.temporal_errors.WorkerConnectionError.code class-attribute

code: str = 'WORKER_CONNECTION_ERROR'

archipy.models.errors.temporal_errors.WorkerConnectionError.message_en class-attribute

message_en: str = 'Failed to connect to Temporal server'

archipy.models.errors.temporal_errors.WorkerConnectionError.message_fa class-attribute

message_fa: str = 'خطا در اتصال به سرور Temporal'

archipy.models.errors.temporal_errors.WorkerConnectionError.http_status class-attribute

http_status: int = (
    HTTPStatus.SERVICE_UNAVAILABLE.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 503
)

archipy.models.errors.temporal_errors.WorkerConnectionError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.UNAVAILABLE.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.UNAVAILABLE.value, tuple)
    else StatusCode.UNAVAILABLE.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 14
)

archipy.models.errors.temporal_errors.WorkerConnectionError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.temporal_errors.WorkerConnectionError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.temporal_errors.WorkerConnectionError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.temporal_errors.WorkerConnectionError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.temporal_errors.WorkerConnectionError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

archipy.models.errors.temporal_errors.WorkerShutdownError

Bases: TemporalError

Exception raised when a worker fails to shutdown gracefully.

Source code in archipy/models/errors/temporal_errors.py
class WorkerShutdownError(TemporalError):
    """Exception raised when a worker fails to shutdown gracefully."""

    code: ClassVar[str] = "WORKER_SHUTDOWN_ERROR"
    message_en: ClassVar[str] = "Failed to shutdown Temporal worker gracefully"
    message_fa: ClassVar[str] = "خطا در خاموش‌سازی صحیح کارگر Temporal"
    http_status: ClassVar[int] = (
        HTTPStatus.INTERNAL_SERVER_ERROR.value if HTTP_AVAILABLE and HTTPStatus is not None else 500
    )
    grpc_status: ClassVar[int] = (
        StatusCode.INTERNAL.value[0]
        if GRPC_AVAILABLE and StatusCode is not None and isinstance(StatusCode.INTERNAL.value, tuple)
        else (StatusCode.INTERNAL.value if GRPC_AVAILABLE and StatusCode is not None else 13)
    )

    def __init__(
        self,
        additional_data: dict[str, Any] | None = None,
    ) -> None:
        """Initialize the worker shutdown error."""
        super().__init__(additional_data=additional_data)

archipy.models.errors.temporal_errors.WorkerShutdownError.code class-attribute

code: str = 'WORKER_SHUTDOWN_ERROR'

archipy.models.errors.temporal_errors.WorkerShutdownError.message_en class-attribute

message_en: str = (
    "Failed to shutdown Temporal worker gracefully"
)

archipy.models.errors.temporal_errors.WorkerShutdownError.message_fa class-attribute

message_fa: str = (
    "خطا در خاموش\u200cسازی صحیح کارگر Temporal"
)

archipy.models.errors.temporal_errors.WorkerShutdownError.http_status class-attribute

http_status: int = (
    HTTPStatus.INTERNAL_SERVER_ERROR.value
    if HTTP_AVAILABLE and HTTPStatus is not None
    else 500
)

archipy.models.errors.temporal_errors.WorkerShutdownError.grpc_status class-attribute

grpc_status: int = (
    StatusCode.INTERNAL.value[0]
    if GRPC_AVAILABLE
    and StatusCode is not None
    and isinstance(StatusCode.INTERNAL.value, tuple)
    else StatusCode.INTERNAL.value
    if GRPC_AVAILABLE and StatusCode is not None
    else 13
)

archipy.models.errors.temporal_errors.WorkerShutdownError.lang instance-attribute

lang = getattr(get_settings(), 'LANGUAGE', LanguageType.FA)

archipy.models.errors.temporal_errors.WorkerShutdownError.additional_data instance-attribute

additional_data = additional_data or {}

archipy.models.errors.temporal_errors.WorkerShutdownError.message property

message: str

Gets the current language message.

Returns:

Name Type Description
str str

The error message in the current language.

archipy.models.errors.temporal_errors.WorkerShutdownError.get_message

get_message() -> str

Gets the localized error message based on the language setting.

Returns:

Name Type Description
str str

The error message in the current language.

Source code in archipy/models/errors/base_error.py
def get_message(self) -> str:
    """Gets the localized error message based on the language setting.

    Returns:
        str: The error message in the current language.
    """
    return self.message_fa if self.lang == LanguageType.FA else self.message_en

archipy.models.errors.temporal_errors.WorkerShutdownError.to_dict

to_dict() -> dict[str, Any]

Converts the exception to a dictionary format for API responses.

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing error details and additional data.

Source code in archipy/models/errors/base_error.py
def to_dict(self) -> dict[str, Any]:
    """Converts the exception to a dictionary format for API responses.

    Returns:
        dict: A dictionary containing error details and additional data.
    """
    # Get the processed message (not the template)
    processed_message = self.get_message()

    response = {
        "error": self.code,
        "detail": {
            "code": self.code,
            "message": processed_message,
            "http_status": self.http_status,
            "grpc_status": self.grpc_status,
        },
    }

    # Add additional data if present
    if self.additional_data:
        detail = response["detail"]
        if isinstance(detail, dict):
            detail.update(self.additional_data)

    return response

options: show_root_toc_entry: false heading_level: 3