Skip to content

Commit

Permalink
handle urllib2.HTTPError (bug 681078)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Balogh committed Aug 22, 2011
1 parent 207fde1 commit e55725b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/devhub/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ def failed_validation(*messages):
def _fetch_manifest(url):
try:
response = urllib2.urlopen(url, timeout=5)
except urllib2.HTTPError, e:
raise Exception(_('%s responded with %s (%s).') % (url, e.code, e.msg))
except urllib2.URLError, e:
# Unpack the URLError to try and find a useful message.
if isinstance(e.reason, socket.timeout):
Expand Down
7 changes: 7 additions & 0 deletions apps/devhub/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,10 @@ def test_response_too_large(self):
with self.assertRaises(Exception):
fetch_manifest('url', self.upload.pk)
self.check_validation('Your manifest must be less than 2097152 bytes.')

def test_http_error(self):
self.urlopen_mock.side_effect = urllib2.HTTPError(
'url', 404, 'Not Found', [], None)
with self.assertRaises(Exception):
fetch_manifest('url', self.upload.pk)
self.check_validation('url responded with 404 (Not Found).')

0 comments on commit e55725b

Please sign in to comment.