diff options
author | Daniel Schadt <kingdread@gmx.de> | 2022-11-17 23:15:00 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2022-11-17 23:15:00 +0100 |
commit | bfda955e95d4bac178ee61205bd626d188bde457 (patch) | |
tree | 1b6c2db74ccdaa8c20949885b1c5cba545e899b0 | |
parent | 45e6b84b818b1d729e558e811a3020d8fd3ca3b9 (diff) | |
download | fietsboek-bfda955e95d4bac178ee61205bd626d188bde457.tar.gz fietsboek-bfda955e95d4bac178ee61205bd626d188bde457.tar.bz2 fietsboek-bfda955e95d4bac178ee61205bd626d188bde457.zip |
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.
-rw-r--r-- | fietsboek/views/tileproxy.py | 8 |
1 files changed, 7 insertions, 1 deletions
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)) |