feat: project skeleton
- infra (k8s, kind, helm, docker) backbone is implemented - security: implementation + unit tests are done
This commit is contained in:
59
app/core/exceptions.py
Normal file
59
app/core/exceptions.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""Custom HTTP exceptions for the API."""
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class NotFoundError(HTTPException):
|
||||
"""Resource not found."""
|
||||
|
||||
def __init__(self, detail: str = "Resource not found") -> None:
|
||||
super().__init__(status_code=status.HTTP_404_NOT_FOUND, detail=detail)
|
||||
|
||||
|
||||
class ConflictError(HTTPException):
|
||||
"""Conflict with current state (e.g., version mismatch)."""
|
||||
|
||||
def __init__(self, detail: str = "Conflict with current state") -> None:
|
||||
super().__init__(status_code=status.HTTP_409_CONFLICT, detail=detail)
|
||||
|
||||
|
||||
class UnauthorizedError(HTTPException):
|
||||
"""Authentication required or failed."""
|
||||
|
||||
def __init__(self, detail: str = "Not authenticated") -> None:
|
||||
super().__init__(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail=detail,
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
|
||||
|
||||
class ForbiddenError(HTTPException):
|
||||
"""Insufficient permissions."""
|
||||
|
||||
def __init__(self, detail: str = "Insufficient permissions") -> None:
|
||||
super().__init__(status_code=status.HTTP_403_FORBIDDEN, detail=detail)
|
||||
|
||||
|
||||
class BadRequestError(HTTPException):
|
||||
"""Invalid request data."""
|
||||
|
||||
def __init__(self, detail: str = "Invalid request") -> None:
|
||||
super().__init__(status_code=status.HTTP_400_BAD_REQUEST, detail=detail)
|
||||
|
||||
|
||||
class ValidationError(HTTPException):
|
||||
"""Validation failed."""
|
||||
|
||||
def __init__(self, detail: str = "Validation failed") -> None:
|
||||
super().__init__(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=detail)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"BadRequestError",
|
||||
"ConflictError",
|
||||
"ForbiddenError",
|
||||
"NotFoundError",
|
||||
"UnauthorizedError",
|
||||
"ValidationError",
|
||||
]
|
||||
Reference in New Issue
Block a user