File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -679,8 +679,6 @@ def handle_error(self, e):
679
679
:param Exception e: the raised Exception object
680
680
681
681
"""
682
- got_request_exception .send (current_app ._get_current_object (), exception = e )
683
-
684
682
# When propagate_exceptions is set, do not return the exception to the
685
683
# client if a handler is configured for the exception.
686
684
if (
@@ -710,6 +708,10 @@ def handle_error(self, e):
710
708
)
711
709
break
712
710
else :
711
+ # Flask docs say: "This signal is not sent for HTTPException or other exceptions that have error handlers
712
+ # registered, unless the exception was raised from an error handler."
713
+ got_request_exception .send (current_app ._get_current_object (), exception = e )
714
+
713
715
if isinstance (e , HTTPException ):
714
716
code = HTTPStatus (e .code )
715
717
if include_message_in_response :
Original file line number Diff line number Diff line change @@ -444,6 +444,27 @@ def record(sender, exception):
444
444
finally :
445
445
got_request_exception .disconnect (record , app )
446
446
447
+ def test_handle_error_signal_does_not_call_got_request_exception (self , app ):
448
+ api = restx .Api (app )
449
+
450
+ exception = BadRequest ()
451
+
452
+ recorded = []
453
+
454
+ def record (sender , exception ):
455
+ recorded .append (exception )
456
+
457
+ @api .errorhandler (BadRequest )
458
+ def handle_bad_request (error ):
459
+ return {"message" : str (error ), "value" : "test" }, 400
460
+
461
+ got_request_exception .connect (record , app )
462
+ try :
463
+ api .handle_error (exception )
464
+ assert len (recorded ) == 0
465
+ finally :
466
+ got_request_exception .disconnect (record , app )
467
+
447
468
def test_handle_error (self , app ):
448
469
api = restx .Api (app )
449
470
You can’t perform that action at this time.
0 commit comments