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
19 changes: 14 additions & 5 deletions sentry_sdk/integrations/bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
from typing import Optional
from bottle import FileUpload, FormsDict, LocalRequest # type: ignore

from bottle import Bottle, Route, request as bottle_request # type: ignore
from bottle import (
Bottle,
Route,
request as bottle_request,
HTTPResponse,
) # type: ignore


class BottleIntegration(Integration):
Expand Down Expand Up @@ -94,16 +99,20 @@ def patched_make_callback(self, *args, **kwargs):
return prepared_callback

def wrapped_callback(*args, **kwargs):
try:
res = prepared_callback(*args, **kwargs)
except Exception as exception:
hub = Hub.current
def capture_exception(exception):
event, hint = event_from_exception(
exception,
client_options=hub.client.options,
mechanism={"type": "bottle", "handled": False},
)
hub.capture_event(event, hint=hint)

try:
res = prepared_callback(*args, **kwargs)
except HTTPResponse:
raise
except Exception as exception:
capture_exception(exception)
raise exception

return res
Expand Down
21 changes: 20 additions & 1 deletion tests/integrations/bottle/test_bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
pytest.importorskip("bottle")

from io import BytesIO
from bottle import Bottle, debug as set_debug, abort
from bottle import Bottle, debug as set_debug, abort, redirect
from sentry_sdk import capture_message

from sentry_sdk.integrations.logging import LoggingIntegration
Expand Down Expand Up @@ -423,3 +423,22 @@ def index():
client.get("/")

assert not events


def test_no_exception_on_redirect(sentry_init, capture_events, app, get_client):
sentry_init(integrations=[bottle_sentry.BottleIntegration()])
events = capture_events()

@app.route("/")
def index():
redirect("/here")

@app.route("/here")
def here():
return "here"

client = get_client()

client.get("/")

assert not events
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ envlist =
{py3.5,py3.6,py3.7}-django-{2.0,2.1}
{pypy,py2.7,py3.5}-django-1.11
{pypy,py2.7,py3.4,py3.5}-django-{1.8,1.9,1.10}
{pypy,py2.7,py3.4,py3.5}-django-1.8
{pypy,py2.7,py3.4}-django-1.7
{pypy,py2.7}-django-1.6

Expand Down