comparison mercurial/httppeer.py @ 37550:b5862ee01abe

httppeer: move error handling and response wrapping into sendrequest This is common for all HTTP requests. It should be part of sendrequest(). Differential Revision: https://phab.mercurial-scm.org/D3235
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 10 Apr 2018 12:12:07 -0700
parents 66d1001e1500
children 946eb204ba67
comparison
equal deleted inserted replaced
37549:66d1001e1500 37550:b5862ee01abe
282 length = len(data) 282 length = len(data)
283 dbg(line % ' %d bytes of data' % length) 283 dbg(line % ' %d bytes of data' % length)
284 284
285 start = util.timer() 285 start = util.timer()
286 286
287 res = opener.open(req) 287 try:
288 if ui.configbool('devel', 'debug.peer-request'): 288 res = opener.open(req)
289 dbg(line % ' finished in %.4f seconds (%s)' 289 except urlerr.httperror as inst:
290 % (util.timer() - start, res.code)) 290 if inst.code == 401:
291 raise error.Abort(_('authorization failed'))
292 raise
293 except httplib.HTTPException as inst:
294 ui.debug('http error requesting %s\n' %
295 util.hidepassword(req.get_full_url()))
296 ui.traceback()
297 raise IOError(None, inst)
298 finally:
299 if ui.configbool('devel', 'debug.peer-request'):
300 dbg(line % ' finished in %.4f seconds (%s)'
301 % (util.timer() - start, res.code))
302
303 # Insert error handlers for common I/O failures.
304 _wraphttpresponse(res)
291 305
292 return res 306 return res
293 307
294 class httppeer(wireproto.wirepeer): 308 class httppeer(wireproto.wirepeer):
295 def __init__(self, ui, path, url, opener, requestbuilder): 309 def __init__(self, ui, path, url, opener, requestbuilder):
344 358
345 req, cu, qs = makev1commandrequest(self.ui, self._requestbuilder, 359 req, cu, qs = makev1commandrequest(self.ui, self._requestbuilder,
346 self._caps, self.capable, 360 self._caps, self.capable,
347 self._url, cmd, args) 361 self._url, cmd, args)
348 362
349 try: 363 resp = sendrequest(self.ui, self._urlopener, req)
350 resp = sendrequest(self.ui, self._urlopener, req)
351 except urlerr.httperror as inst:
352 if inst.code == 401:
353 raise error.Abort(_('authorization failed'))
354 raise
355 except httplib.HTTPException as inst:
356 self.ui.debug('http error while sending %s command\n' % cmd)
357 self.ui.traceback()
358 raise IOError(None, inst)
359
360 # Insert error handlers for common I/O failures.
361 _wraphttpresponse(resp)
362 364
363 # record the url we got redirected to 365 # record the url we got redirected to
364 resp_url = pycompat.bytesurl(resp.geturl()) 366 resp_url = pycompat.bytesurl(resp.geturl())
365 if resp_url.endswith(qs): 367 if resp_url.endswith(qs):
366 resp_url = resp_url[:-len(qs)] 368 resp_url = resp_url[:-len(qs)]