From bfda955e95d4bac178ee61205bd626d188bde457 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 17 Nov 2022 23:15:00 +0100 Subject: tileproxy: relay HTTP status codes This is nice if we hit a 404 or something on the source, especially with user-configured sources. As a small side, we now don't give the client the URL in the error message, as that could contain API keys that we don't want to leak. --- fietsboek/views/tileproxy.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fietsboek/views/tileproxy.py b/fietsboek/views/tileproxy.py index ff68e30..cbd84f0 100644 --- a/fietsboek/views/tileproxy.py +++ b/fietsboek/views/tileproxy.py @@ -229,8 +229,14 @@ def tile_proxy(request): LOGGER.debug("Proxy timeout when accessing %r", url) request.redis.incr(timeout_tracker) request.redis.expire(timeout_tracker, PUNISHMENT_TTL) - return HTTPGatewayTimeout(f"No response in time from {url}") + return HTTPGatewayTimeout(f"No response in time from {provider}") else: + try: + resp.raise_for_status() + except requests.HTTPError as exc: + LOGGER.info("Proxy request failed for %s: %s", provider, exc) + return Response(f"Failed to get tile from {provider}", + status_code=resp.status_code) request.redis.set(cache_key, resp.content, ex=TTL) return Response(resp.content, content_type=resp.headers.get("Content-type", content_type)) -- cgit v1.2.3