Skip to content

Commit 78db2ec

Browse files
authored
fix(bottle): Prevent internal error on 404 (#4131)
`request.route` can throw a `RuntimeError: This request is not connected to a route.`. Closes #3583
1 parent 4c9731b commit 78db2ec

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

sentry_sdk/integrations/bottle.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,20 @@ def _set_transaction_name_and_source(event, transaction_style, request):
177177
name = ""
178178

179179
if transaction_style == "url":
180-
name = request.route.rule or ""
180+
try:
181+
name = request.route.rule or ""
182+
except RuntimeError:
183+
pass
181184

182185
elif transaction_style == "endpoint":
183-
name = (
184-
request.route.name
185-
or transaction_from_function(request.route.callback)
186-
or ""
187-
)
186+
try:
187+
name = (
188+
request.route.name
189+
or transaction_from_function(request.route.callback)
190+
or ""
191+
)
192+
except RuntimeError:
193+
pass
188194

189195
event["transaction"] = name
190196
event["transaction_info"] = {"source": SOURCE_FOR_STYLE[transaction_style]}

0 commit comments

Comments
 (0)