Skip to content

Commit dea88bb

Browse files
committed
Revise exception handling doc on error handler functions
Document that a sync error-handler function is run in a threadpool. Extend the add_error_handler function's Pydoc.
1 parent 2e6ffab commit dea88bb

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

connexion/middleware/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,8 @@ def add_error_handler(
452452
453453
:param code_or_exception: An exception class or the status code of HTTP exceptions to
454454
handle.
455-
:param function: Callable that will handle exception and return a HTTP problem response.
456-
An async coroutine has access to the stack traceback. A sync function has no access
457-
to the stack traceback because it is run in a threadpool.
455+
:param function: Callable that will handle the exception and return a ConnexionResponse such
456+
as a `connexion.problem.problem`. May be async; a sync function is run in a threadpool.
458457
"""
459458
if self.middleware_stack is not None:
460459
raise RuntimeError(

docs/exceptions.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,8 @@ You can register error handlers on:
115115

116116
.. note::
117117

118-
All the error handlers shown above are sync functions. The exception stack trace is
119-
not available in a sync function because the middleware runs it in a threadpool.
120-
121-
Error handlers can be ``async`` coroutines as well. Use a coroutine if the handler
122-
function needs the stack trace from the exception, for example to log a traceback.
118+
Error handlers can be ``async`` coroutines as well. If the error handler needs to log
119+
the exception, pass the exception using the Python logger's ``exc_info`` parameter.
123120

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

0 commit comments

Comments
 (0)