From: Oleg Broytman Date: Sun, 6 Jul 2014 01:39:54 +0000 (+0400) Subject: Handle HTTPException and IOError (socket errors) X-Git-Tag: v4.6.0~5 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=b4dc970296be1f8e78c548424d3f3561db2d9410;p=bookmarks_db.git Handle HTTPException and IOError (socket errors) Log all errors. --- diff --git a/Robots/bkmk_rurllib2.py b/Robots/bkmk_rurllib2.py index b15a7b0..49c5568 100644 --- a/Robots/bkmk_rurllib2.py +++ b/Robots/bkmk_rurllib2.py @@ -14,7 +14,7 @@ __all__ = ['robot_urllib2'] import sys import httplib import urllib2 -from Robots.bkmk_robot_base import robot_base +from Robots.bkmk_robot_base import robot_base, get_error opener = urllib2.OpenerDirector() @@ -53,9 +53,19 @@ class robot_urllib2(robot_base): if e.code in (301, 302, 303, 307): return None, e.code, e.hdrs['Location'], None, None else: + self.log(' HTTP Error %s: %s' % (e.code, e.msg)) return "HTTP Error %s: %s" % (e.code, e.msg), None, None, None, None except urllib2.URLError, e: + self.log(' URL Error: %s' % e.reason) return "URL Error: %s" % e.reason, None, None, None, None + except httplib.HTTPException, e: + error = get_error(e) + self.log(' HTTP Exception: %s' % error) + return "HTTP Exception: %s" % error, None, None, None, None + except IOError, e: + error = get_error(e) + self.log(' I/O Error: %s' % error) + return "I/O Error: %s" % error, None, None, None, None else: return None, None, None, response.info(), response.read()