
- Setup project structure with FastAPI, SQLAlchemy, and SQLite - Create Todo model and database migrations - Implement CRUD API endpoints - Add error handling and validation - Update README with documentation and examples generated with BackendIM... (backend.im)
22 lines
696 B
Python
22 lines
696 B
Python
from fastapi import HTTPException, status
|
|
|
|
class TodoNotFoundException(HTTPException):
|
|
def __init__(self, todo_id: int):
|
|
super().__init__(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail=f"Todo with ID {todo_id} not found",
|
|
)
|
|
|
|
class ValidationError(HTTPException):
|
|
def __init__(self, detail: str):
|
|
super().__init__(
|
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
detail=detail,
|
|
)
|
|
|
|
class DatabaseError(HTTPException):
|
|
def __init__(self, detail: str = "Database error occurred"):
|
|
super().__init__(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
detail=detail,
|
|
) |