INNER CODE UNIT · Python
general_exception_handler
Xeron2000/openOii · backend/app/main.py:92
async def general_exception_handler(request: Request, exc: Exception):
"""处理未捕获的异常"""
logger.exception(
f"Unhandled exception: {str(exc)}",
extra={
"path": request.url.path,
"method": request.method,
},
)
# 开发环境返回详细错误,生产环境只返回友好消息
details = {"error": str(exc)} if settings.environment == "development" else {}
return JSONResponse(
status_code=500,
content={
"error": {
"code": "INTERNAL_ERROR",
"message": "服务器内部错误,请稍后重试",
"details": details,