refactors
This commit is contained in:
parent
139a5fbef3
commit
f46d2ae8b3
12 changed files with 734 additions and 536 deletions
61
backend/exceptions.py
Normal file
61
backend/exceptions.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
"""Standardized API exception classes for consistent error responses.
|
||||
|
||||
Note: These exceptions use string detail for backward compatibility with existing tests.
|
||||
Future refactoring could standardize on structured error responses.
|
||||
"""
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class APIError(HTTPException):
|
||||
"""Base API error with consistent structure.
|
||||
|
||||
Uses string detail for backward compatibility with existing tests.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
status_code: int,
|
||||
message: str,
|
||||
):
|
||||
super().__init__(status_code=status_code, detail=message)
|
||||
|
||||
|
||||
class NotFoundError(APIError):
|
||||
"""Resource not found error (404)."""
|
||||
|
||||
def __init__(self, resource: str):
|
||||
super().__init__(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
message=f"{resource} not found",
|
||||
)
|
||||
|
||||
|
||||
class ConflictError(APIError):
|
||||
"""Conflict error (409)."""
|
||||
|
||||
def __init__(self, message: str):
|
||||
super().__init__(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
message=message,
|
||||
)
|
||||
|
||||
|
||||
class BadRequestError(APIError):
|
||||
"""Bad request error (400)."""
|
||||
|
||||
def __init__(self, message: str):
|
||||
super().__init__(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
message=message,
|
||||
)
|
||||
|
||||
|
||||
class ServiceUnavailableError(APIError):
|
||||
"""Service unavailable error (503)."""
|
||||
|
||||
def __init__(self, message: str):
|
||||
super().__init__(
|
||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
message=message,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue