From c25cf7494edd6f0c361daadae9ea3d84837c9694 Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Fri, 6 Jun 2014 11:57:43 -0700 Subject: [PATCH] Fix bug in error handler when response is None Regression introduced in #298. --- botocore/handlers.py | 4 ++++ tests/unit/test_handlers.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/botocore/handlers.py b/botocore/handlers.py index 0e12114107..4270f781b6 100644 --- a/botocore/handlers.py +++ b/botocore/handlers.py @@ -53,6 +53,10 @@ def check_for_200_error(response, operation, **kwargs): # 500 response (with respect to raising exceptions, retries, etc.) # We're connected *before* all the other retry logic handlers, so as long # as we switch the error code to 500, we'll retry the error as expected. + if response is None: + # A None response can happen if an exception is raised while + # trying to retrieve the response. See Endpoint._get_response(). + return http_response, parsed = response if http_response.status_code == 200: if 'Errors' in parsed: diff --git a/tests/unit/test_handlers.py b/tests/unit/test_handlers.py index e4c02664f2..98bb6460e8 100644 --- a/tests/unit/test_handlers.py +++ b/tests/unit/test_handlers.py @@ -125,6 +125,11 @@ def test_200_response_with_no_error_left_untouched(self): # We don't touch the status code since there are no errors present. self.assertEqual(http_response.status_code, 200) + def test_500_response_can_be_none(self): + # A 500 response can raise an exception, which means the response + # object is None. We need to handle this case. + check_for_200_error(None, mock.Mock()) + class TestRetryHandlerOrder(BaseSessionTest): def get_handler_names(self, responses):