54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
from typing import Any, Dict, Optional
|
|
|
|
from fastapi import HTTPException, status
|
|
|
|
|
|
class TaskManagerException(HTTPException):
|
|
"""Base exception for the Task Manager API."""
|
|
|
|
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 TaskNotFoundException(TaskManagerException):
|
|
"""Exception raised when a task is not found."""
|
|
|
|
def __init__(
|
|
self,
|
|
detail: Any = "Task not found",
|
|
headers: Optional[Dict[str, Any]] = None,
|
|
) -> None:
|
|
super().__init__(
|
|
status_code=status.HTTP_404_NOT_FOUND, detail=detail, headers=headers
|
|
)
|
|
|
|
|
|
class ValidationException(TaskManagerException):
|
|
"""Exception raised when validation fails."""
|
|
|
|
def __init__(
|
|
self,
|
|
detail: Any = "Validation error",
|
|
headers: Optional[Dict[str, Any]] = None,
|
|
) -> None:
|
|
super().__init__(
|
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=detail, headers=headers
|
|
)
|
|
|
|
|
|
class DatabaseException(TaskManagerException):
|
|
"""Exception raised when a database operation fails."""
|
|
|
|
def __init__(
|
|
self,
|
|
detail: Any = "Database operation failed",
|
|
headers: Optional[Dict[str, Any]] = None,
|
|
) -> None:
|
|
super().__init__(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=detail, headers=headers
|
|
) |