feat: initial commit

This commit is contained in:
2025-05-09 19:15:53 +05:30
commit 80c61dc127
54 changed files with 2195 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
from .api_exceptions import ApiException
from .business_exception import BusinessValidationException
from .validation_exception import ValidationException
from .forbidden_exception import ForbiddenException
from .internal_server_error_exception import InternalServerErrorException
from .resource_not_found_exception import ResourceNotFoundException
from .unauthorized_exception import UnauthorizedException
__all__ = [
"ApiException",
"BusinessValidationException",
"ValidationException",
"ForbiddenException",
"InternalServerErrorException",
"ResourceNotFoundException",
"UnauthorizedException",
]
+7
View File
@@ -0,0 +1,7 @@
class ApiException(Exception):
"""Base API exception class for HTTP errors."""
def __init__(self, status_code: int, message: str):
self.status_code = status_code
self.message = message
super().__init__(self.message)
+6
View File
@@ -0,0 +1,6 @@
class BusinessValidationException(Exception):
"""Exception for business logic validation errors."""
def __init__(self, message: str):
self.message = message
super().__init__(self.message)
+9
View File
@@ -0,0 +1,9 @@
from http import HTTPStatus
from .api_exceptions import ApiException
class ForbiddenException(ApiException):
"""Exception for forbidden access errors."""
def __init__(self, message: str = "Forbidden"):
super().__init__(HTTPStatus.FORBIDDEN, message)
@@ -0,0 +1,12 @@
from http import HTTPStatus
from .api_exceptions import ApiException
class InternalServerErrorException(ApiException):
"""Exception for internal server errors."""
def __init__(self):
super().__init__(
HTTPStatus.INTERNAL_SERVER_ERROR,
"An unexpected error has occurred. Please contact the administrator."
)
@@ -0,0 +1,9 @@
from http import HTTPStatus
from .api_exceptions import ApiException
class ResourceNotFoundException(ApiException):
"""Exception for resource not found errors."""
def __init__(self, message: str):
super().__init__(HTTPStatus.NOT_FOUND, message)
+9
View File
@@ -0,0 +1,9 @@
from http import HTTPStatus
from .api_exceptions import ApiException
class UnauthorizedException(ApiException):
"""Exception for unauthorized access errors."""
def __init__(self, message: str = "Failed to authenticate."):
super().__init__(HTTPStatus.UNAUTHORIZED, message)
+6
View File
@@ -0,0 +1,6 @@
class ValidationException(Exception):
"""Exception for data validation errors."""
def __init__(self, message: str):
self.message = message
super().__init__(self.message)