from fastapi import FastAPI, Request from fastapi.responses import JSONResponse from app.core.logger import logger import traceback def add_global_exception_handlers(app: FastAPI): @app.exception_handler(Exception) async def global_exception_handler(request: Request, exc: Exception): logger.error(f"CRITICAL SYSTEM CRASH: {request.method} {request.url.path}") logger.error(traceback.format_exc()) return JSONResponse( status_code=500, content={ "error": "An unexpected internal server error occurred. Our team has been notified.", "code": "INTERNAL_SERVER_ERROR" } )