Browse Source

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.
merge-requests/55/head
Deimos 6 years ago
parent
commit
06976a62e9
  1. 4
      tildes/tildes/__init__.py

4
tildes/tildes/__init__.py

@ -120,6 +120,10 @@ def metrics_tween_factory(handler: Callable, registry: Registry) -> Callable:
response = handler(request) response = handler(request)
duration = time() - start_time duration = time() - start_time
# ignore requests for invalid addresses
if not request.matched_route:
return response
request_histogram.labels( request_histogram.labels(
route=request.matched_route.name, route=request.matched_route.name,
status_code=response.status_code, status_code=response.status_code,

Loading…
Cancel
Save