Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: rietveld.py

Issue 1681333005: Raise exceptions properly on HTTP errors from OAuthRpcServer (which is only used on bots) (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: All 200s are successes Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/rietveld_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: rietveld.py
diff --git a/rietveld.py b/rietveld.py
index 9adc9c5ca1346a99c79552dc62ae77c17c576871..22168f572709de041fb17d18020c590ea2cadb44 100644
--- a/rietveld.py
+++ b/rietveld.py
@@ -21,6 +21,7 @@ import logging
import re
import socket
import ssl
+import StringIO
import sys
import time
import urllib
@@ -409,23 +410,20 @@ class Rietveld(object):
if m:
# Fake an HTTPError exception. Cheezy. :(
raise urllib2.HTTPError(
- request_path, int(m.group(1)), msg, None, None)
+ request_path, int(m.group(1)), msg, None, StringIO.StringIO())
old_error_exit(msg)
upload.ErrorExit = trap_http_500
for retry in xrange(self._maxtries):
try:
logging.debug('%s' % request_path)
- result = self.rpc_server.Send(request_path, **kwargs)
- # Sometimes GAE returns a HTTP 200 but with HTTP 500 as the content.
- # How nice.
- return result
+ return self.rpc_server.Send(request_path, **kwargs)
except urllib2.HTTPError, e:
if retry >= (self._maxtries - 1):
raise
- flake_codes = [500, 502, 503]
+ flake_codes = {500, 502, 503}
if retry_on_404:
- flake_codes.append(404)
+ flake_codes.add(404)
if e.code not in flake_codes:
raise
except urllib2.URLError, e:
@@ -440,10 +438,10 @@ class Rietveld(object):
# The reason can be a string or another exception, e.g.,
# socket.error or whatever else.
reason_as_str = str(e.reason)
- for retry_anyway in [
+ for retry_anyway in (
'Name or service not known',
'EOF occurred in violation of protocol',
- 'timed out']:
+ 'timed out'):
if retry_anyway in reason_as_str:
return True
return False # Assume permanent otherwise.
@@ -528,6 +526,11 @@ class OAuthRpcServer(object):
payload: request is a POST if not None, GET otherwise
timeout: in seconds
extra_headers: (dict)
+
+ Returns: the HTTP response body as a string
+
+ Raises:
+ urllib2.HTTPError
"""
# This method signature should match upload.py:AbstractRpcServer.Send()
method = 'GET'
@@ -543,7 +546,6 @@ class OAuthRpcServer(object):
try:
if timeout:
self._http.timeout = timeout
- # TODO(pgervais) implement some kind of retry mechanism (see upload.py).
url = self.host + request_path
if kwargs:
url += "?" + urllib.urlencode(kwargs)
@@ -572,6 +574,11 @@ class OAuthRpcServer(object):
continue
break
+ if ret[0].status >= 300:
+ raise urllib2.HTTPError(
+ request_path, int(ret[0]['status']), ret[1], None,
+ StringIO.StringIO())
+
return ret[1]
finally:
« no previous file with comments | « no previous file | tests/rietveld_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698