File tree Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1010from sentry_sdk .integrations .logging import ignore_logger
1111
1212from sanic import Sanic
13+ from sanic .exceptions import SanicException
1314from sanic .router import Router
1415from sanic .handlers import ErrorHandler
1516
@@ -94,6 +95,9 @@ async def sentry_wrapped_error_handler(request, exception):
9495
9596
9697def _capture_exception (exception ):
98+ if isinstance (exception , SanicException ):
99+ return
100+
97101 hub = Hub .current
98102 integration = hub .get_integration (SanicIntegration )
99103 if integration is None :
Original file line number Diff line number Diff line change 55
66flask = pytest .importorskip ("flask" )
77
8- from flask import Flask , request
8+ from flask import Flask , request , abort
99
1010from flask_login import LoginManager , login_user
1111
@@ -445,3 +445,18 @@ def error_handler(err):
445445
446446 exception , = event2 ["exception" ]["values" ]
447447 assert exception ["type" ] == "ZeroDivisionError"
448+
449+
450+ def test_bad_request_not_captured (sentry_init , capture_events , app ):
451+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
452+ events = capture_events ()
453+
454+ @app .route ("/" )
455+ def index ():
456+ abort (400 )
457+
458+ client = app .test_client ()
459+
460+ client .get ("/" )
461+
462+ assert not events
Original file line number Diff line number Diff line change 77from sentry_sdk .integrations .sanic import SanicIntegration
88
99from sanic import Sanic , request , response
10+ from sanic .exceptions import abort
1011
1112
1213@pytest .fixture
@@ -73,6 +74,20 @@ def myerror(request):
7374 )
7475
7576
77+ def test_bad_request_not_captured (sentry_init , app , capture_events ):
78+ sentry_init (integrations = [SanicIntegration ()])
79+ events = capture_events ()
80+
81+ @app .route ("/" )
82+ def index (request ):
83+ abort (400 )
84+
85+ request , response = app .test_client .get ("/" )
86+ assert response .status == 400
87+
88+ assert not events
89+
90+
7691def test_error_in_errorhandler (sentry_init , app , capture_events ):
7792 sentry_init (integrations = [SanicIntegration ()])
7893 events = capture_events ()
You can’t perform that action at this time.
0 commit comments