Skip to content

Commit 39f34e0

Browse files
authored
Merge pull request #261 from OpenTreeOfLife/smarter-caching-logic
Clean up caching logic (don't swallow 4xx responses)
2 parents 11682b2 + a21f2f0 commit 39f34e0

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

phylesystem_api/phylesystem_api/views/default.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ def fetch_and_cache(url):
167167
msg = "... and now we're back with fetched, which is a {}"
168168
msg = msg.format(type(fetched))
169169
_LOG.warning(msg)
170-
fetched.raise_for_status()
171170
fetched.encoding = "utf-8" # Optional: requests infers this internally
172171

173172
# modify or discard "hop-by-hop" headers
@@ -180,8 +179,8 @@ def fetch_and_cache(url):
180179
ct = "text/plain"
181180
return Response(
182181
headers=fetched.headers,
183-
body=fetched.text, # missing JSON payload will raise an error
184-
status="200 OK",
182+
body=fetched.text,
183+
status_code=fetched.status_code, # keep the returned status code!
185184
charset="UTF-8",
186185
content_type=ct,
187186
)
@@ -192,7 +191,7 @@ def fetch_and_cache(url):
192191
raise HTTPException(body=str(e))
193192
except Exception as e:
194193
_LOG.warning(" UNKNOWN request exception: {}".format(str(e)))
195-
raise HTTPBadRequest(body="Unknown exception in cached call!")
194+
raise HTTPBadRequest(body="Unknown exception in cached call! Check server log for details.")
196195

197196
_LOG.warning("...trying to fetch-and-cache...")
198197
return fetch_and_cache(target_url)

0 commit comments

Comments
 (0)