This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to catch Exception
via exception_handlers since FastAPI 0.70.0
#4025
Comments
The Exception cannot be used for this purpose. You can inherit it tho |
Exception
via exception_handlers since FastAPI 0.69.0Exception
via exception_handlers since FastAPI
It works fine in 0.68.2 My use case: I`m trying to catch all unknown exceptions in code and responsing with JSON =) I think issue is relating to 0.69.0 (with new Starlette 0.15.0 and AnyIO) |
You're right. I guess I put in my mind that is a "cannot" because Starlette will log the traceback if you use try to handle In any case, I cannot reproduce on Python 3.8, jfyk. |
As a side note, I can't seem to catch the exceptions from a websocket endpoint in fastapi==0.68.2
The stack trace
App creation
|
Exception
via exception_handlers since FastAPIException
via exception_handlers since FastAPI 0.69.0
Exception
via exception_handlers since FastAPI 0.69.0Exception
via exception_handlers since FastAPI 0.70.0
Same use case here, wanting to always return JSON even with generic exception. It seems to because of new starlette version encode/starlette#1175. |
Same here. |
Same here. Pinning starlette to the version 0.14.2 fixed the issue. |
Fixed by encode/starlette#1262. |
I'm eagerly looking forward to #4145 getting merged. 😄 |
No... This is not fixed... |
@Kludex did you validate against the just-released FastAPI 0.71.0 and confirm this is still an issue? |
@phillipuniverse Using FastAPI 0.73.0 we're still facing such an issue |
Using 0.78, I cannot reproduce. I see a JSON response in my browser using the code in OP. |
We're facing this issue in tests, using the AsyncClient. Could you please try that? |
Would you mind providing a minimal reproducible example? 🙏 |
Facing a similar issue using FastAPI 0.80 and Starlette 0.19.1. The FastAPI app handles the Exception and returns JSON, but logs a stack trace with the following code:
The stack trace is identical to the above (only containing my unhandled error instead of Interestingly, if I convert the exception handler to middleware, there's no logged stack trace. I'd rather use the error handler, though.
Problem: an ASGI error gets logged with a stack trace when I try to handle Exception with an exception handler. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
First Check
Commit to Help
Example Code
Description
/call_me
Internal 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
The text was updated successfully, but these errors were encountered: