TalentaTalkBackend / app /core /exceptions.py
vithariumz's picture
Deploy: Initial Backend Release v1.0
52f5a2a
from fastapi import HTTPException, status
from typing import Any, Optional
class AppError(HTTPException):
def __init__(
self,
status_code: int,
detail: Any = None,
headers: Optional[dict[str, Any]] = None,
) -> None:
super().__init__(status_code=status_code, detail=detail, headers=headers)
class NotFoundError(AppError):
def __init__(self, resource: str = "Resource"):
super().__init__(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"{resource} not found"
)
class AuthenticationError(AppError):
def __init__(self, detail: str = "Could not validate credentials"):
super().__init__(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=detail,
headers={"WWW-Authenticate": "Bearer"},
)
class DuplicateError(AppError):
def __init__(self, detail: str = "Data already exists"):
super().__init__(
status_code=status.HTTP_409_CONFLICT,
detail=detail
)