Details
When an errorhandler is registered on a namespace, and PROPAGATE_EXCEPTIONS is set to True in the Flask app, then the namespace handler will not catch the exceptions. It looks like this is due to the handle_error function not checking the error handlers that exist in any child classes.
Code
api.py:653
if (
not isinstance(e, HTTPException)
and current_app.propagate_exceptions
and not isinstance(e, tuple(self.error_handlers.keys()))
):
Should check for potential error handlers in the class and child classes:
if (
not isinstance(e, HTTPException)
and current_app.propagate_exceptions
and not isinstance(e, tuple(self._own_and_child_error_handlers.keys()))
):
Repro Steps (if applicable)
- Set
propagate_exceptions=True in the app
- Create a namespace, and register it to the API
- Add a
@namespace.errorhandler function
- Raise error in a route, which won't get caught by namespace's error handler
Expected Behavior
Error handler defined on a namespace should still catch exceptions when propagate_exceptions is True.
Details
When an
errorhandleris registered on a namespace, andPROPAGATE_EXCEPTIONSis set toTruein the Flask app, then the namespace handler will not catch the exceptions. It looks like this is due to thehandle_errorfunction not checking the error handlers that exist in any child classes.Code
api.py:653Should check for potential error handlers in the class and child classes:
Repro Steps (if applicable)
propagate_exceptions=Truein the app@namespace.errorhandlerfunctionExpected Behavior
Error handler defined on a namespace should still catch exceptions when
propagate_exceptionsisTrue.