1
0
mirror of https://github.com/sjlongland/tornado-news.git synced 2025-09-13 18:13:16 +10:00

If read fails, fall back to cache.

We can probably factor this a bit better so we're not repeating
ourselves, but in essence, if we have an older version we can put up
instead, we'll use that.
This commit is contained in:
Stuart Longland 2016-03-06 16:54:55 +10:00
parent 16ad2d14e1
commit 0d5546abd4
Signed by: stuartl
GPG Key ID: 4DFA191410BDE3B7

View File

@ -222,13 +222,22 @@ class FeedFetcher(object):
self._log.debug('Body type: %s (cache)', type(body)) self._log.debug('Body type: %s (cache)', type(body))
else: else:
# Check for exceptions try:
response.rethrow() # Check for exceptions
response.rethrow()
# Grab body data # Grab body data
body = response.body body = response.body
cached = False cached = False
self._log.debug('Body type: %s (http)', type(body)) self._log.debug('Body type: %s (http)', type(body))
except:
if cache_dir is not None:
self._log.warning(
'Failed to retrieve %s (%s), trying cache', name, url)
body = open(path.join(cache_dir, 'body'),'rb').read()
cached = True
else:
raise
# Dump to cache # Dump to cache
if cache_dir is not None: if cache_dir is not None: