From 06976a62e96d418c62ab756ed4ee4960daaa34f0 Mon Sep 17 00:00:00 2001 From: Deimos Date: Fri, 18 Jan 2019 20:55:09 -0700 Subject: [PATCH] Metrics tween: ignore requests without a route I'm seeing some errors come through now when requests for unhandled urls (things like /ads.txt) are made, usually just by various bots/scanners. The metrics tween is crashing on these, so this should fix it. --- tildes/tildes/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tildes/tildes/__init__.py b/tildes/tildes/__init__.py index 6c348d1..548fc84 100644 --- a/tildes/tildes/__init__.py +++ b/tildes/tildes/__init__.py @@ -120,6 +120,10 @@ def metrics_tween_factory(handler: Callable, registry: Registry) -> Callable: response = handler(request) duration = time() - start_time + # ignore requests for invalid addresses + if not request.matched_route: + return response + request_histogram.labels( route=request.matched_route.name, status_code=response.status_code,