# TypeError: ValueError 类型的对象不可 JSON 序列化

- **ID:** `python/fastapi-http-exception-detail-not-serializable`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

HTTPException 的 detail 传入了不可序列化的对象（如异常实例），而不是字符串或字典。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   raise HTTPException(status_code=400, detail=str(e))
   ```
2. **** (90% 成功率)
   ```
   raise HTTPException(400, detail={'error': 'bad_input', 'message': str(e)})
   ```

## 无效尝试

- **** — Loses error context and clients get an empty body. (70% 失败率)
- **** — Leaks internals and is fragile across exception types. (80% 失败率)
