feat: initial commit
This commit is contained in:
@@ -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",
|
||||
]
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -0,0 +1,6 @@
|
||||
class ValidationException(Exception):
|
||||
"""Exception for data validation errors."""
|
||||
|
||||
def __init__(self, message: str):
|
||||
self.message = message
|
||||
super().__init__(self.message)
|
||||
Reference in New Issue
Block a user