First Check
Commit to Help
Example Code
################################################
#
# Pay attention: below is Python 3.10 syntax
#
################################################
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from pydantic import ValidationError
async def internal_server_error(request: Request, exc: Exception | ValidationError) -> "JSONResponse":
return JSONResponse(content={"detail": "Internal Server Error"}, status_code=500)
app = FastAPI(
exception_handlers={
Exception: internal_server_error,
ValidationError: internal_server_error,
},
)
@app.get("/call_me")
async def raise_exception() -> None:
raise Exception("I am exception.")
Description
- Open the browser and call the endpoint:
/call_me
- It returns plain text:
Internal Server Error
- But I excepted it return JSON:
{"detail": "Internal Server Error"}
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.70.0
Python Version
Python 3.10.0
Additional Context
It works fine on FastAPI 0.68.2.
Issue is also affected 0.69.0
First Check
Commit to Help
Example Code
Description
/call_meInternal Server Error{"detail": "Internal Server Error"}Operating System
Linux
Operating System Details
No response
FastAPI Version
0.70.0
Python Version
Python 3.10.0
Additional Context
It works fine on FastAPI 0.68.2.
Issue is also affected 0.69.0