33 lines
989 B
Python
33 lines
989 B
Python
from __future__ import annotations
|
|
|
|
|
|
class AppException(Exception):
|
|
def __init__(self, status_code: int, detail: str):
|
|
self.status_code = status_code
|
|
self.detail = detail
|
|
|
|
|
|
class NotFoundException(AppException):
|
|
def __init__(self, detail: str = "Resource not found"):
|
|
super().__init__(status_code=404, detail=detail)
|
|
|
|
|
|
class UnauthorizedException(AppException):
|
|
def __init__(self, detail: str = "Not authenticated"):
|
|
super().__init__(status_code=401, detail=detail)
|
|
|
|
|
|
class ForbiddenException(AppException):
|
|
def __init__(self, detail: str = "Permission denied"):
|
|
super().__init__(status_code=403, detail=detail)
|
|
|
|
|
|
class ConflictException(AppException):
|
|
def __init__(self, detail: str = "Resource already exists"):
|
|
super().__init__(status_code=409, detail=detail)
|
|
|
|
|
|
class ValidationException(AppException):
|
|
def __init__(self, detail: str = "Validation error"):
|
|
super().__init__(status_code=422, detail=detail)
|