# 属性错误：'HTTPException' 对象没有 'detail' 属性。

- **ID:** `python/fastapi-http-exception-handler-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

自定义异常处理器中错误地访问了 `exc.detail`，但该属性不存在或名称错误。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   在异常处理器中使用 `exc.detail` 获取错误信息，如 `return JSONResponse(status_code=exc.status_code, content={"detail": exc.detail})`。
   ```
2. **** (90% 成功率)
   ```
   确保导入 `from fastapi import HTTPException` 并使用正确的属性。
   ```

## 无效尝试

- **** — 尝试使用 `exc.message` 但实际属性为 `detail`，导致 AttributeError。 (70% 失败率)
- **** — 在异常处理器中未正确导入 HTTPException，导致类型不匹配。 (50% 失败率)
