Skip to content
Merged
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
2 changes: 1 addition & 1 deletion flask_restx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def handle_error(self, e):
if (
not isinstance(e, HTTPException)
and current_app.propagate_exceptions
and not isinstance(e, tuple(self.error_handlers.keys()))
and not isinstance(e, tuple(self._own_and_child_error_handlers.keys()))
):

exc_type, exc_value, tb = sys.exc_info()
Expand Down
27 changes: 27 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,30 @@ def handle_custom_exception(error):
"message": "error",
"test": "value",
}

def test_namespace_errorhandler_with_propagate_true(self, app, client):
"""Exceptions with errorhandler on a namespace should not be
returned to client, even if PROPAGATE_EXCEPTIONS is set."""
app.config["PROPAGATE_EXCEPTIONS"] = True
api = restx.Api(app)
namespace = restx.Namespace('test_namespace')
api.add_namespace(namespace)

@namespace.route("/test/", endpoint="test")
class TestResource(restx.Resource):
def get(self):
raise RuntimeError("error")

@namespace.errorhandler(RuntimeError)
def handle_custom_exception(error):
return {"message": str(error), "test": "value"}, 400

response = client.get("/test_namespace/test/")
assert response.status_code == 400
assert response.content_type == "application/json"

data = json.loads(response.data.decode("utf8"))
assert data == {
"message": "error",
"test": "value",
}