Reraise exception in yield except block but get FastAPIError finally. #11408
Replies: 3 comments
-
|
It seems you are re-raising an exception that was already caught. Try modifying the code to handle the exception within the block async def redis_session() -> AsyncGenerator[Redis, None]:
async with RedisPool() as client:
try:
yield client
except Exception as e:
logger.warning(f'redis_session error: {traceback.format_exc()}')
raise e # Re-raise the caught exception |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I tried to reproduce your issue, but I didn't succeed. Everything works fine. Can you give a minimal working example that we can run and see that problem? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Closing this. Feel free to reopen it when you are ready to provide more info |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Hi, our teams are considering updating FastAPI to v0.110.1.
After update FastAPI to v0.110.1, we suffer due to FastAPIError.
we use
yieldobject in logic, and reraise exception in except block like below code.We use redis session with
Depends().When we raise custom exception, fastapi return FastAPIError response and we can see below error msg.
We add custom_exception_handler to FastAPI and it is not working...
Also, we return
JSONResponsein custom exception.Please, give me some solutions...
Operating System
macOS
Operating System Details
No response
FastAPI Version
0.110.1
Pydantic Version
2.6.1
Python Version
3.11.8
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions