Таска 3: разделение кастомных эксепшенов #2
@@ -1,11 +1,9 @@
|
||||
from src.application.domain.exceptions.application_exceptions import (
|
||||
ApplicationException,
|
||||
BadRequestException,
|
||||
ConflictException,
|
||||
ForbiddenException,
|
||||
InternalException,
|
||||
NotFoundException,
|
||||
ServiceUnavailableException,
|
||||
TooManyRequestsException,
|
||||
UnauthorizedException,
|
||||
)
|
||||
from src.application.domain.exceptions.application_exceptions import ApplicationException
|
||||
from src.application.domain.exceptions.bad_request_exception import BadRequestException
|
||||
from src.application.domain.exceptions.unauthorized_exception import UnauthorizedException
|
||||
from src.application.domain.exceptions.forbidden_exception import ForbiddenException
|
||||
from src.application.domain.exceptions.not_found_exception import NotFoundException
|
||||
from src.application.domain.exceptions.conflict_exception import ConflictException
|
||||
from src.application.domain.exceptions.internal_exception import InternalException
|
||||
from src.application.domain.exceptions.service_unavailable_exception import ServiceUnavailableException
|
||||
from src.application.domain.exceptions.too_many_requests_exception import TooManyRequestsException
|
||||
|
||||
@@ -17,43 +17,3 @@ class ApplicationException(Exception):
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'{self.status_code}: {self.message}'
|
||||
|
||||
|
||||
class BadRequestException(ApplicationException):
|
||||
def __init__(self, message: str, headers: Mapping[str, str] | None = None):
|
||||
super().__init__(400, message, headers)
|
||||
|
||||
|
||||
class UnauthorizedException(ApplicationException):
|
||||
def __init__(self, message: str = 'Unauthorized', headers: Mapping[str, str] | None = None):
|
||||
super().__init__(401, message, headers)
|
||||
|
||||
|
||||
class ForbiddenException(ApplicationException):
|
||||
def __init__(self, message: str = 'Forbidden', headers: Mapping[str, str] | None = None):
|
||||
super().__init__(403, message, headers)
|
||||
|
||||
|
||||
class NotFoundException(ApplicationException):
|
||||
def __init__(self, message: str = 'Not found', headers: Mapping[str, str] | None = None):
|
||||
super().__init__(404, message, headers)
|
||||
|
||||
|
||||
class ConflictException(ApplicationException):
|
||||
def __init__(self, message: str, headers: Mapping[str, str] | None = None):
|
||||
super().__init__(409, message, headers)
|
||||
|
||||
|
||||
class TooManyRequestsException(ApplicationException):
|
||||
def __init__(self, message: str, headers: Mapping[str, str] | None = None):
|
||||
super().__init__(429, message, headers)
|
||||
|
||||
|
||||
class ServiceUnavailableException(ApplicationException):
|
||||
def __init__(self, message: str, headers: Mapping[str, str] | None = None):
|
||||
super().__init__(503, message, headers)
|
||||
|
||||
|
||||
class InternalException(ApplicationException):
|
||||
def __init__(self, message: str = 'Internal Server Error', headers: Mapping[str, str] | None = None):
|
||||
super().__init__(500, message, headers)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
from application.domain.exceptions.application_exceptions import ApplicationException
|
||||
|
||||
from typing import Mapping
|
||||
|
||||
|
||||
class BadRequestException(ApplicationException):
|
||||
def __init__(self, message: str, headers: Mapping[str, str] | None = None):
|
||||
super().__init__(400, message, headers)
|
||||
8
src/application/domain/exceptions/conflict_exception.py
Normal file
8
src/application/domain/exceptions/conflict_exception.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from application.domain.exceptions.application_exceptions import ApplicationException
|
||||
|
||||
from typing import Mapping
|
||||
|
||||
|
||||
class ConflictException(ApplicationException):
|
||||
def __init__(self, message: str, headers: Mapping[str, str] | None = None):
|
||||
super().__init__(409, message, headers)
|
||||
8
src/application/domain/exceptions/forbidden_exception.py
Normal file
8
src/application/domain/exceptions/forbidden_exception.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from application.domain.exceptions.application_exceptions import ApplicationException
|
||||
|
||||
from typing import Mapping
|
||||
|
||||
|
||||
class ForbiddenException(ApplicationException):
|
||||
def __init__(self, message: str = 'Forbidden', headers: Mapping[str, str] | None = None):
|
||||
super().__init__(403, message, headers)
|
||||
8
src/application/domain/exceptions/internal_exception.py
Normal file
8
src/application/domain/exceptions/internal_exception.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from application.domain.exceptions.application_exceptions import ApplicationException
|
||||
|
||||
from typing import Mapping
|
||||
|
||||
|
||||
class InternalException(ApplicationException):
|
||||
def __init__(self, message: str = 'Internal Server Error', headers: Mapping[str, str] | None = None):
|
||||
super().__init__(500, message, headers)
|
||||
8
src/application/domain/exceptions/not_found_exception.py
Normal file
8
src/application/domain/exceptions/not_found_exception.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from application.domain.exceptions.application_exceptions import ApplicationException
|
||||
|
||||
from typing import Mapping
|
||||
|
||||
|
||||
class NotFoundException(ApplicationException):
|
||||
def __init__(self, message: str = 'Not found', headers: Mapping[str, str] | None = None):
|
||||
super().__init__(404, message, headers)
|
||||
@@ -0,0 +1,8 @@
|
||||
from application.domain.exceptions.application_exceptions import ApplicationException
|
||||
|
||||
from typing import Mapping
|
||||
|
||||
|
||||
class ServiceUnavailableException(ApplicationException):
|
||||
def __init__(self, message: str, headers: Mapping[str, str] | None = None):
|
||||
super().__init__(503, message, headers)
|
||||
@@ -0,0 +1,8 @@
|
||||
from application.domain.exceptions.application_exceptions import ApplicationException
|
||||
|
||||
from typing import Mapping
|
||||
|
||||
|
||||
class TooManyRequestsException(ApplicationException):
|
||||
def __init__(self, message: str, headers: Mapping[str, str] | None = None):
|
||||
super().__init__(429, message, headers)
|
||||
@@ -0,0 +1,8 @@
|
||||
from application.domain.exceptions.application_exceptions import ApplicationException
|
||||
|
||||
from typing import Mapping
|
||||
|
||||
|
||||
class UnauthorizedException(ApplicationException):
|
||||
def __init__(self, message: str = 'Unauthorized', headers: Mapping[str, str] | None = None):
|
||||
super().__init__(401, message, headers)
|
||||
Reference in New Issue
Block a user