Patchwork D3235: httppeer: move error handling and response wrapping into sendrequest

login
register
mail settings
Submitter phabricator
Date April 11, 2018, 1:29 a.m.
Message ID <differential-rev-PHID-DREV-xg4vxudabww46hnyy6af-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/30662/
State Superseded
Headers show

Comments

phabricator - April 11, 2018, 1:29 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is common for all HTTP requests. It should be part of
  sendrequest().

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3235

AFFECTED FILES
  mercurial/httppeer.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -284,10 +284,24 @@ 
 
         start = util.timer()
 
-    res = opener.open(req)
-    if ui.configbool('devel', 'debug.peer-request'):
-        dbg(line % '  finished in %.4f seconds (%s)'
-            % (util.timer() - start, res.code))
+    try:
+        res = opener.open(req)
+    except urlerr.httperror as inst:
+        if inst.code == 401:
+            raise error.Abort(_('authorization failed'))
+        raise
+    except httplib.HTTPException as inst:
+        ui.debug('http error requesting %s\n' %
+                 util.hidepassword(req.get_full_url()))
+        ui.traceback()
+        raise IOError(None, inst)
+    finally:
+        if ui.configbool('devel', 'debug.peer-request'):
+            dbg(line % '  finished in %.4f seconds (%s)'
+                % (util.timer() - start, res.code))
+
+    # Insert error handlers for common I/O failures.
+    _wraphttpresponse(res)
 
     return res
 
@@ -346,19 +360,7 @@ 
                                            self._caps, self.capable,
                                            self._url, cmd, args)
 
-        try:
-            resp = sendrequest(self.ui, self._urlopener, req)
-        except urlerr.httperror as inst:
-            if inst.code == 401:
-                raise error.Abort(_('authorization failed'))
-            raise
-        except httplib.HTTPException as inst:
-            self.ui.debug('http error while sending %s command\n' % cmd)
-            self.ui.traceback()
-            raise IOError(None, inst)
-
-        # Insert error handlers for common I/O failures.
-        _wraphttpresponse(resp)
+        resp = sendrequest(self.ui, self._urlopener, req)
 
         # record the url we got redirected to
         resp_url = pycompat.bytesurl(resp.geturl())