feedcell: do not fail if service is not available (#21383)

This commit is contained in:
Lauréline Guérin 2019-10-22 11:19:02 +02:00
parent 8f0bc9a059
commit 82503cdd7d
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 14 additions and 4 deletions

View File

@ -930,10 +930,15 @@ class FeedCell(CellBase):
cache_key = hashlib.md5(smart_bytes(self.url)).hexdigest()
feed_content = cache.get(cache_key)
if not feed_content:
feed_response = requests.get(utils.get_templated_url(self.url))
if feed_response.status_code == 200:
feed_content = feed_response.content
cache.set(cache_key, feed_content, 600)
try:
feed_response = requests.get(utils.get_templated_url(self.url))
feed_response.raise_for_status()
except (requests.exceptions.RequestException):
pass
else:
if feed_response.status_code == 200:
feed_content = feed_response.content
cache.set(cache_key, feed_content, 600)
if feed_content:
extra_context['feed'] = feedparser.parse(feed_content)
if self.limit:

View File

@ -21,6 +21,7 @@ try:
import mellon
except ImportError:
mellon = None
import requests
from combo.wsgi import application
from combo.data.models import (Page, CellBase, TextCell, ParentContentCell,
@ -743,6 +744,10 @@ def test_synchronous_placeholder(app):
resp = app.get('/foo/', status=200)
assert resp.text.count('data-ajax-cell-must-load="true"') == 1
requests_get.side_effect = requests.exceptions.ConnectionError()
resp = app.get('/foo/', status=200)
def test_redirects(app):
Redirect.objects.all().delete()
Page.objects.all().delete()