File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -666,7 +666,7 @@ def handle_error(self, e):
666
666
if (
667
667
not isinstance (e , HTTPException )
668
668
and current_app .propagate_exceptions
669
- and not isinstance (e , tuple (self .error_handlers .keys ()))
669
+ and not isinstance (e , tuple (self ._own_and_child_error_handlers .keys ()))
670
670
):
671
671
672
672
exc_type , exc_value , tb = sys .exc_info ()
Original file line number Diff line number Diff line change @@ -653,3 +653,30 @@ def handle_custom_exception(error):
653
653
"message" : "error" ,
654
654
"test" : "value" ,
655
655
}
656
+
657
+ def test_namespace_errorhandler_with_propagate_true (self , app , client ):
658
+ """Exceptions with errorhandler on a namespace should not be
659
+ returned to client, even if PROPAGATE_EXCEPTIONS is set."""
660
+ app .config ["PROPAGATE_EXCEPTIONS" ] = True
661
+ api = restx .Api (app )
662
+ namespace = restx .Namespace ('test_namespace' )
663
+ api .add_namespace (namespace )
664
+
665
+ @namespace .route ("/test/" , endpoint = "test" )
666
+ class TestResource (restx .Resource ):
667
+ def get (self ):
668
+ raise RuntimeError ("error" )
669
+
670
+ @namespace .errorhandler (RuntimeError )
671
+ def handle_custom_exception (error ):
672
+ return {"message" : str (error ), "test" : "value" }, 400
673
+
674
+ response = client .get ("/test_namespace/test/" )
675
+ assert response .status_code == 400
676
+ assert response .content_type == "application/json"
677
+
678
+ data = json .loads (response .data .decode ("utf8" ))
679
+ assert data == {
680
+ "message" : "error" ,
681
+ "test" : "value" ,
682
+ }
You can’t perform that action at this time.
0 commit comments