Skip to content
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

Revise exception handling doc on error handler functions #2021

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion connexion/middleware/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ def add_error_handler(

:param code_or_exception: An exception class or the status code of HTTP exceptions to
handle.
:param function: Callable that will handle exception, may be async.
:param function: Callable that will handle exception and return a HTTP problem response.
An async coroutine has access to the stack traceback. A sync function has no access
to the stack traceback because it is run in a threadpool.
"""
if self.middleware_stack is not None:
raise RuntimeError(
Expand Down
8 changes: 6 additions & 2 deletions docs/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ You can register error handlers on:

.. warning::

⚠️ **The following is not recommended as it complicates the exception handling logic,**
⚠️ **The following is not recommended as it complicates the exception handling logic!**

You can also register error handlers on the underlying flask application directly.

Expand Down Expand Up @@ -115,7 +115,11 @@ You can register error handlers on:

.. note::

Error handlers can be ``async`` coroutines as well.
All the error handlers shown above are sync functions. The exception stack trace is
not available in a sync function because the middleware runs it in a threadpool.

Error handlers can be ``async`` coroutines as well. Use a coroutine if the handler
function needs the stack trace from the exception, for example to log a traceback.

.. _Flask documentation: https://flask.palletsprojects.com/en/latest/errorhandling/#error-handlers

Expand Down
Loading