# TypeError: Object of type HTTPException is not JSON serializable

- **ID:** `python/fastapi-http-exception-not-json`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A route returned an HTTPException instance instead of raising it, so FastAPI tried to serialize the exception object as the response body.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 0.100+ | active | — | — |

## Workarounds

1. **** (98% success)
   ```
   raise HTTPException(status_code=404, detail='Not found')
   ```
2. **** (90% success)
   ```
   from fastapi.responses import JSONResponse
return JSONResponse(status_code=404, content={'detail': 'Not found'})
   ```

## Dead Ends

- **** — Returns a 200 with exception internals in the body instead of an error status. (85% fail)
- **** — Leaks stack/details and still uses the wrong status code. (70% fail)
