add_exception_handler
type annotation does not accept coroutines
#2399
Unanswered
fpiche
asked this question in
Potential Issue
Replies: 1 comment
-
I'm going thought this exact same problem. Thing is when adding multiple exception handlers to the FastAPI object then it won't be clean at all, one could use the |
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.
-
A related discussion was answered here but does not fully describe my issue #2391
Since the introduction of the
ExceptionHandler
type, a coroutine cannot be passed toadd_exception_handler
.Example:
I have an async function with signature
and am passing it to
add_exception_handler
like so:But mypy is complaining that I’m passing the wrong type:
A workaround i found for now is to add exception handlers during app creation since I'm using FastAPI:
FastAPI(exception_handlers={HTTPException: exc_handler})
since this accepts the coroutine type.Beta Was this translation helpful? Give feedback.
All reactions