Automated Action 29d75cdf08 Implement Task Management API with FastAPI and SQLite
- Set up project structure and dependencies
- Create database models and schemas for tasks
- Implement CRUD operations for tasks
- Add API endpoints for task management
- Create Alembic migrations for the database
- Add health check endpoint
- Implement error handling
- Add documentation in README.md
2025-05-17 11:20:00 +00:00

46 lines
1.1 KiB
Python

from typing import Any, Dict, Optional
from fastapi import HTTPException, status
class TaskException(HTTPException):
"""Base Task API exception."""
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 TaskNotFound(TaskException):
"""Exception raised when a task is not found."""
def __init__(
self,
task_id: int,
headers: Optional[Dict[str, Any]] = None,
) -> None:
super().__init__(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Task with ID {task_id} not found",
headers=headers,
)
class InvalidTaskData(TaskException):
"""Exception raised when task data is invalid."""
def __init__(
self,
detail: str = "Invalid task data",
headers: Optional[Dict[str, Any]] = None,
) -> None:
super().__init__(
status_code=status.HTTP_400_BAD_REQUEST,
detail=detail,
headers=headers,
)