1
0
mirror of https://github.com/sjlongland/tornado-news.git synced 2025-09-13 10:03:14 +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))
else:
# Check for exceptions
response.rethrow()
try:
# Check for exceptions
response.rethrow()
# Grab body data
body = response.body
cached = False
self._log.debug('Body type: %s (http)', type(body))
# Grab body data
body = response.body
cached = False
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
if cache_dir is not None: