- Bootstrap script for creating monorepo projects - FastAPI backend templates with uv, ruff, mypy, pytest - React frontend templates with TypeScript, ESLint, Prettier - Docker Compose setup with backend, frontend, and database - 9 development and CI scripts - Gitea Actions CI/CD workflows - Comprehensive documentation (8 files) - 45 template files for complete project structure - Automated verification script (all tests pass) - Based on coding-agent-rules standards
59 lines
1.3 KiB
Python
59 lines
1.3 KiB
Python
"""Error handling utilities."""
|
|
|
|
from typing import Any
|
|
|
|
from fastapi import HTTPException, status
|
|
|
|
|
|
class AppException(Exception):
|
|
"""Base application exception."""
|
|
|
|
def __init__(self, message: str, details: dict[str, Any] | None = None) -> None:
|
|
"""Initialize exception."""
|
|
self.message = message
|
|
self.details = details or {}
|
|
super().__init__(self.message)
|
|
|
|
|
|
class NotFoundError(AppException):
|
|
"""Resource not found error."""
|
|
|
|
pass
|
|
|
|
|
|
class ValidationError(AppException):
|
|
"""Validation error."""
|
|
|
|
pass
|
|
|
|
|
|
class AuthenticationError(AppException):
|
|
"""Authentication error."""
|
|
|
|
pass
|
|
|
|
|
|
def raise_not_found(resource: str, identifier: str | int) -> None:
|
|
"""Raise HTTP 404 exception."""
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail=f"{resource} with id '{identifier}' not found",
|
|
)
|
|
|
|
|
|
def raise_validation_error(message: str) -> None:
|
|
"""Raise HTTP 422 exception."""
|
|
raise HTTPException(
|
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
detail=message,
|
|
)
|
|
|
|
|
|
def raise_unauthorized(message: str = "Unauthorized") -> None:
|
|
"""Raise HTTP 401 exception."""
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail=message,
|
|
headers={"WWW-Authenticate": "Bearer"},
|
|
)
|