Skip to content

Namespace error handlers broken when propagate_exceptions=True #285

@mjreiss

Description

@mjreiss

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)

  1. Set propagate_exceptions=True in the app
  2. Create a namespace, and register it to the API
  3. Add a @namespace.errorhandler function
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions