feat: add custom exceptions
This commit is contained in:
@@ -1 +1,21 @@
|
||||
from src.application.domain.exceptions.application_exceptions import ApplicationException
|
||||
from src.application.domain.exceptions.application_exception import ApplicationException
|
||||
from src.application.domain.exceptions.bad_gateway_exception import BadGatewayException
|
||||
from src.application.domain.exceptions.bad_request_exception import BadRequestException
|
||||
from src.application.domain.exceptions.conflict_exception import ConflictException
|
||||
from src.application.domain.exceptions.forbidden_exception import ForbiddenException
|
||||
from src.application.domain.exceptions.internal_server_exception import InternalServerException
|
||||
from src.application.domain.exceptions.not_found_exception import NotFoundException
|
||||
from src.application.domain.exceptions.service_unavailable_exception import ServiceUnavailableException
|
||||
from src.application.domain.exceptions.unauthorized_exception import UnauthorizedException
|
||||
|
||||
__all__ = [
|
||||
'ApplicationException',
|
||||
'BadGatewayException',
|
||||
'BadRequestException',
|
||||
'ConflictException',
|
||||
'ForbiddenException',
|
||||
'InternalServerException',
|
||||
'NotFoundException',
|
||||
'ServiceUnavailableException',
|
||||
'UnauthorizedException',
|
||||
]
|
||||
@@ -7,12 +7,13 @@ class ApplicationException(Exception):
|
||||
self,
|
||||
status_code: int,
|
||||
message: str,
|
||||
headers: Mapping[str, str] | None = None,
|
||||
headers: Mapping[str,str] | None = None,
|
||||
):
|
||||
super().__init__(message)
|
||||
self.status_code = status_code
|
||||
self.message = message
|
||||
self.headers = headers
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.status_code}: {self.message}'
|
||||
12
src/application/domain/exceptions/bad_gateway_exception.py
Normal file
12
src/application/domain/exceptions/bad_gateway_exception.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
from typing import Mapping
|
||||
from src.application.domain.exceptions.application_exception import ApplicationException
|
||||
|
||||
|
||||
class BadGatewayException(ApplicationException):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = 'Bad Gateway',
|
||||
headers: Mapping[str,str] | None = None,
|
||||
):
|
||||
super().__init__(status_code=502,message=message,headers=headers)
|
||||
12
src/application/domain/exceptions/bad_request_exception.py
Normal file
12
src/application/domain/exceptions/bad_request_exception.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
from typing import Mapping
|
||||
from src.application.domain.exceptions.application_exception import ApplicationException
|
||||
|
||||
|
||||
class BadRequestException(ApplicationException):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = 'Bad Request',
|
||||
headers: Mapping[str,str] | None = None,
|
||||
):
|
||||
super().__init__(status_code=400,message=message,headers=headers)
|
||||
12
src/application/domain/exceptions/conflict_exception.py
Normal file
12
src/application/domain/exceptions/conflict_exception.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
from typing import Mapping
|
||||
from src.application.domain.exceptions.application_exception import ApplicationException
|
||||
|
||||
|
||||
class ConflictException(ApplicationException):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = 'Conflict',
|
||||
headers: Mapping[str,str] | None = None,
|
||||
):
|
||||
super().__init__(status_code=409,message=message,headers=headers)
|
||||
12
src/application/domain/exceptions/forbidden_exception.py
Normal file
12
src/application/domain/exceptions/forbidden_exception.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
from typing import Mapping
|
||||
from src.application.domain.exceptions.application_exception import ApplicationException
|
||||
|
||||
|
||||
class ForbiddenException(ApplicationException):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = 'Forbidden',
|
||||
headers: Mapping[str,str] | None = None,
|
||||
):
|
||||
super().__init__(status_code=403,message=message,headers=headers)
|
||||
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
from typing import Mapping
|
||||
from src.application.domain.exceptions.application_exception import ApplicationException
|
||||
|
||||
|
||||
class InternalServerException(ApplicationException):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = 'Internal Server Error',
|
||||
headers: Mapping[str,str] | None = None,
|
||||
):
|
||||
super().__init__(status_code=500,message=message,headers=headers)
|
||||
12
src/application/domain/exceptions/not_found_exception.py
Normal file
12
src/application/domain/exceptions/not_found_exception.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
from typing import Mapping
|
||||
from src.application.domain.exceptions.application_exception import ApplicationException
|
||||
|
||||
|
||||
class NotFoundException(ApplicationException):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = 'Not Found',
|
||||
headers: Mapping[str,str] | None = None,
|
||||
):
|
||||
super().__init__(status_code=404,message=message,headers=headers)
|
||||
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
from typing import Mapping
|
||||
from src.application.domain.exceptions.application_exception import ApplicationException
|
||||
|
||||
|
||||
class ServiceUnavailableException(ApplicationException):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = 'Service Unavailable',
|
||||
headers: Mapping[str,str] | None = None,
|
||||
):
|
||||
super().__init__(status_code=503,message=message,headers=headers)
|
||||
12
src/application/domain/exceptions/unauthorized_exception.py
Normal file
12
src/application/domain/exceptions/unauthorized_exception.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
from typing import Mapping
|
||||
from src.application.domain.exceptions.application_exception import ApplicationException
|
||||
|
||||
|
||||
class UnauthorizedException(ApplicationException):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = 'Unauthorized',
|
||||
headers: Mapping[str,str] | None = None,
|
||||
):
|
||||
super().__init__(status_code=401,message=message,headers=headers)
|
||||
Reference in New Issue
Block a user