Handle requests TooManyRedirects and other errors
@@ -64,7 +64,15 @@ class EmbedAPIBase(CachedResponseMixin, APIView):
log.debug('Cached response. url=%s', url)
return cached_response
+ try:
response = requests.get(url, timeout=1)
+ except requests.exceptions.TooManyRedirects:
+ log.warning('Too many redirects. url=%s', url)
+ return
+ except Exception: # noqa
+ log.warning('There was an error reading the URL requested. url=%s', url)
+ return
+
if response.ok:
cache.set(url, response.text, timeout=60 * 5)
return response.text
