37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from fastapi import HTTPException, status
|
|
|
|
|
|
class NotFoundError(HTTPException):
|
|
"""Exception raised when a resource is not found."""
|
|
|
|
def __init__(self, detail: str = "Resource not found"):
|
|
super().__init__(status_code=status.HTTP_404_NOT_FOUND, detail=detail)
|
|
|
|
|
|
class BadRequestError(HTTPException):
|
|
"""Exception raised for bad requests."""
|
|
|
|
def __init__(self, detail: str = "Bad request"):
|
|
super().__init__(status_code=status.HTTP_400_BAD_REQUEST, detail=detail)
|
|
|
|
|
|
class UnauthorizedError(HTTPException):
|
|
"""Exception raised for unauthorized access attempts."""
|
|
|
|
def __init__(self, detail: str = "Not authorized"):
|
|
super().__init__(status_code=status.HTTP_401_UNAUTHORIZED, detail=detail)
|
|
|
|
|
|
class ForbiddenError(HTTPException):
|
|
"""Exception raised for forbidden access attempts."""
|
|
|
|
def __init__(self, detail: str = "Forbidden"):
|
|
super().__init__(status_code=status.HTTP_403_FORBIDDEN, detail=detail)
|
|
|
|
|
|
class ConflictError(HTTPException):
|
|
"""Exception raised for resource conflicts."""
|
|
|
|
def __init__(self, detail: str = "Resource conflict"):
|
|
super().__init__(status_code=status.HTTP_409_CONFLICT, detail=detail)
|