Automated Action fec0fa72e7 Initial project setup with FastAPI, SQLite, and Alembic
- Set up SQLite database configuration and directory structure
- Configure Alembic for proper SQLite migrations
- Add initial model schemas and API endpoints
- Fix OAuth2 authentication
- Implement proper code formatting with Ruff
2025-05-27 20:34:02 +00:00

73 lines
2.0 KiB
Python

from typing import Any, Dict, Optional
from fastapi import HTTPException, status
class WeatherAPIException(HTTPException):
"""Custom exception for the Weather 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 WeatherServiceException(WeatherAPIException):
"""Exception for weather service errors."""
def __init__(
self,
detail: str = "Weather service error",
status_code: int = status.HTTP_503_SERVICE_UNAVAILABLE,
) -> None:
super().__init__(status_code=status_code, detail=detail)
class NotFoundException(WeatherAPIException):
"""Exception for resources not found."""
def __init__(
self,
detail: str = "Resource not found",
) -> None:
super().__init__(status_code=status.HTTP_404_NOT_FOUND, detail=detail)
class ForbiddenException(WeatherAPIException):
"""Exception for forbidden actions."""
def __init__(
self,
detail: str = "Not enough permissions",
) -> None:
super().__init__(status_code=status.HTTP_403_FORBIDDEN, detail=detail)
class BadRequestException(WeatherAPIException):
"""Exception for bad requests."""
def __init__(
self,
detail: str = "Bad request",
) -> None:
super().__init__(status_code=status.HTTP_400_BAD_REQUEST, detail=detail)
class UnauthorizedException(WeatherAPIException):
"""Exception for unauthorized requests."""
def __init__(
self,
detail: str = "Not authenticated",
headers: Optional[Dict[str, Any]] = None,
) -> None:
if not headers:
headers = {"WWW-Authenticate": "Bearer"}
super().__init__(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=detail,
headers=headers
)