8000 fix(sanic): Don't report 400 as error · etherscan-io/sentry-python@b50b0b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit b50b0b3

Browse files
committed
fix(sanic): Don't report 400 as error
Fix getsentry#127
1 parent 658f022 commit b50b0b3

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

sentry_sdk/integrations/sanic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from sentry_sdk.integrations.logging import ignore_logger
1111

1212
from sanic import Sanic
13+
from sanic.exceptions import SanicException
1314
from sanic.router import Router
1415
from sanic.handlers import ErrorHandler
1516

@@ -94,6 +95,9 @@ async def sentry_wrapped_error_handler(request, exception):
9495

9596

9697
def _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:

tests/integrations/flask/test_flask.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
flask = pytest.importorskip("flask")
77

8-
from flask import Flask, request
8+
from flask import Flask, request, abort
99

1010
from 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

tests/integrations/sanic/test_sanic.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sentry_sdk.integrations.sanic import SanicIntegration
88

99
from 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+
7691
def test_error_in_errorhandler(sentry_init, app, capture_events):
7792
sentry_init(integrations=[SanicIntegration()])
7893
events = capture_events()

0 commit comments

Comments
 (0)
0