- Add centralized exception classes - Validate signature request status before signing - Check contract status before approval/rejection - Add exception handlers to FastAPI app - Update tests for new validation logic Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
30 lines
816 B
Python
30 lines
816 B
Python
"""Exception handlers for FastAPI."""
|
|
from fastapi import Request, status
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from app.core.exceptions import AppException
|
|
|
|
|
|
async def app_exception_handler(request: Request, exc: AppException):
|
|
"""Handle application exceptions."""
|
|
return JSONResponse(
|
|
status_code=status.HTTP_400_BAD_REQUEST,
|
|
content={
|
|
"code": exc.code,
|
|
"message": exc.message,
|
|
"details": exc.details,
|
|
}
|
|
)
|
|
|
|
|
|
async def generic_exception_handler(request: Request, exc: Exception):
|
|
"""Handle generic exceptions."""
|
|
return JSONResponse(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
content={
|
|
"code": 50000,
|
|
"message": "Internal server error",
|
|
"details": {},
|
|
}
|
|
)
|