49 lines
1.2 KiB
Python

from typing import Any, Dict, Optional
from fastapi import HTTPException, status
class AuthError(HTTPException):
"""Authentication error."""
def __init__(
self,
detail: str = "Authentication error",
headers: Optional[Dict[str, Any]] = None,
):
super().__init__(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=detail,
headers=headers or {"WWW-Authenticate": "Bearer"},
)
class ForbiddenError(HTTPException):
"""Permission denied error."""
def __init__(self, detail: str = "Permission denied"):
super().__init__(
status_code=status.HTTP_403_FORBIDDEN,
detail=detail,
)
class NotFoundError(HTTPException):
"""Resource not found error."""
def __init__(self, detail: str = "Resource not found"):
super().__init__(
status_code=status.HTTP_404_NOT_FOUND,
detail=detail,
)
class BadRequestError(HTTPException):
"""Bad request error."""
def __init__(self, detail: str = "Bad request"):
super().__init__(
status_code=status.HTTP_400_BAD_REQUEST,
detail=detail,
)