Skip to content

Commit

Permalink
Avoid failures on requests exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Sep 28, 2017
1 parent 022d5f7 commit 77e57da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sc/social/like/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ def prefetch_facebook(obj, event):

url = obj.absolute_url()
endpoint = 'https://graph.facebook.com/?id=' + url + '&scrape=true'
r = requests.post(endpoint, timeout=5)
try:
r = requests.post(endpoint, timeout=5)
except requests.exceptions.RequestException as e:
logger.warn('Prefetch failure: ' + str(e.message))
return

if r.status_code == '200':
logger.info('Prefetch successful: ' + url)
Expand Down
11 changes: 11 additions & 0 deletions sc/social/like/tests/test_subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ def test_facebook_prefetch_error(self, m, l):
expected = ('sc.social.like', 'WARNING', msg)
l.check(expected)

@requests_mock.mock()
def test_facebook_prefetch_failure(self, m):
import requests
m.post(self.endpoint, exc=requests.exceptions.ConnectTimeout)

with api.env.adopt_roles(['Manager']):
api.content.transition(self.news_item, 'publish')

# transition should not be aborted
self.assertEqual(api.content.get_state(self.news_item), 'published')


def load_tests(loader, tests, pattern):
from sc.social.like.testing import HAS_DEXTERITY
Expand Down

0 comments on commit 77e57da

Please sign in to comment.