OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 try_count = 0 | 245 try_count = 0 |
246 while True: | 246 while True: |
247 response, content = http.request(*args, **kwargs) | 247 response, content = http.request(*args, **kwargs) |
248 try: | 248 try: |
249 content_json = json.loads(content) | 249 content_json = json.loads(content) |
250 except ValueError: | 250 except ValueError: |
251 content_json = None | 251 content_json = None |
252 | 252 |
253 # Buildbucket could return an error even if status==200. | 253 # Buildbucket could return an error even if status==200. |
254 if content_json and content_json.get('error'): | 254 if content_json and content_json.get('error'): |
| 255 error = content_json.get('error') |
| 256 if error.get('code') == 403: |
| 257 raise BuildbucketResponseException( |
| 258 'Access denied: %s' % error.get('message', '')) |
255 msg = 'Error in response. Reason: %s. Message: %s.' % ( | 259 msg = 'Error in response. Reason: %s. Message: %s.' % ( |
256 content_json['error'].get('reason', ''), | 260 error.get('reason', ''), error.get('message', '')) |
257 content_json['error'].get('message', '')) | |
258 raise BuildbucketResponseException(msg) | 261 raise BuildbucketResponseException(msg) |
259 | 262 |
260 if response.status == 200: | 263 if response.status == 200: |
261 if not content_json: | 264 if not content_json: |
262 raise BuildbucketResponseException( | 265 raise BuildbucketResponseException( |
263 'Buildbucket returns invalid json content: %s.\n' | 266 'Buildbucket returns invalid json content: %s.\n' |
264 'Please file bugs at http://crbug.com, label "Infra-BuildBucket".' % | 267 'Please file bugs at http://crbug.com, label "Infra-BuildBucket".' % |
265 content) | 268 content) |
266 return content_json | 269 return content_json |
267 if response.status < 500 or try_count >= 2: | 270 if response.status < 500 or try_count >= 2: |
(...skipping 3693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3961 if __name__ == '__main__': | 3964 if __name__ == '__main__': |
3962 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3965 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3963 # unit testing. | 3966 # unit testing. |
3964 fix_encoding.fix_encoding() | 3967 fix_encoding.fix_encoding() |
3965 colorama.init() | 3968 colorama.init() |
3966 try: | 3969 try: |
3967 sys.exit(main(sys.argv[1:])) | 3970 sys.exit(main(sys.argv[1:])) |
3968 except KeyboardInterrupt: | 3971 except KeyboardInterrupt: |
3969 sys.stderr.write('interrupted\n') | 3972 sys.stderr.write('interrupted\n') |
3970 sys.exit(1) | 3973 sys.exit(1) |
OLD | NEW |