OpenTreeOfLife / phylesystem-api

API access to Open Tree of Life treestore
BSD 2-Clause "Simplified" License
9 stars 5 forks source link

Avoid cache poisoning by raising API-fetch errors #219

Closed jimallman closed 5 years ago

jimallman commented 5 years ago

In order to avoid poisoning our cache with failed API calls, we should preserve any failed response code during API calls, and raise appropriate (web2py-class) exceptions. This will pass the error directly back to the client (and troubleshooters), and ensure that the bad response is ignored by web2py's RAM cache.

N.B. By default, webp2y's RAM cache will ignore any response with status codes other than 1xx, 2xx, 3xx. We can narrow that further to only cache 200 responses, but I believe urllib2 will successfully follow some of the other response types (e.g. redirects) and fill the cache properly.

jimallman commented 5 years ago

FYI - This is now deployed on devapi. In my testing, it correctly ignores the early broken response after deployment, then shows proper behavior a couple of minutes later. (Sadly, the error page does not reload to our default view, so you need to browse back to the homepage to see the happy tree.)

mtholder commented 5 years ago

looks great. thanks, @jimallman !