# fastapi.exceptions.HTTPException: 500 Internal Server Error

- **ID:** `python/fastapi-http-exception-handler-missing`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

FastAPI 应用未处理未捕获的异常，导致返回 500 错误

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## Workarounds

1. **添加全局异常处理器** (95% success)
   ```
   @app.exception_handler(Exception)
async def global_exception_handler(request, exc):
    return JSONResponse(status_code=500, content={'detail': '内部错误'})
   ```
2. **使用中间件捕获未处理异常** (90% success)
   ```
   @app.middleware('http')
async def catch_exceptions(request, call_next):
    try:
        return await call_next(request)
    except Exception:
        return JSONResponse(status_code=500, content={'detail': '错误'})
   ```

## Dead Ends

- **在路径操作中使用 try-except 但不记录日志** — 错误被隐藏，难以调试 (70% fail)
- **返回空响应而不提供错误信息** — 客户端无法知道错误原因 (60% fail)
