From 67f4ab44a8250274aa0a9e5970f566d94aca3b00 Mon Sep 17 00:00:00 2001 From: Christopher Lott <10234212+chrisinmtown@users.noreply.github.com> Date: Fri, 27 Dec 2024 11:09:01 -0500 Subject: [PATCH] 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. Fixes #2019 --- connexion/middleware/main.py | 3 ++- docs/exceptions.rst | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/connexion/middleware/main.py b/connexion/middleware/main.py index 23e3b00aa..1bd050a28 100644 --- a/connexion/middleware/main.py +++ b/connexion/middleware/main.py @@ -452,7 +452,8 @@ 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 the exception and return a ConnexionResponse such + as a `connexion.problem.problem`. May be async; a sync function is run in a threadpool. """ if self.middleware_stack is not None: raise RuntimeError( diff --git a/docs/exceptions.rst b/docs/exceptions.rst index dd77f68f1..15ae0eb7b 100644 --- a/docs/exceptions.rst +++ b/docs/exceptions.rst @@ -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. @@ -115,7 +115,8 @@ You can register error handlers on: .. note:: - Error handlers can be ``async`` coroutines as well. + Error handlers can be ``async`` coroutines as well. If the error handler needs to log + the exception, pass the exception using the Python logger's ``exc_info`` parameter. .. _Flask documentation: https://flask.palletsprojects.com/en/latest/errorhandling/#error-handlers