ai-legal-assistant/backend/app/core/exception_handlers.py
root ae72b180e5 fix: improve error handling and validation
- 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>
2026-05-01 03:38:20 +08:00

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": {},
}
)