From 729d86c4852ce0721e26764a44fc4745109c2b71 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Thu, 3 Aug 2017 14:05:05 -0400 Subject: [PATCH] standardize on 502 for insights errors --- awx/api/views.py | 8 ++++---- awx/main/tests/unit/api/test_views.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index 2ea6c22de4..100540ad6a 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -2100,20 +2100,20 @@ class HostInsights(GenericAPIView): try: res = self._get_insights(url, username, password) except requests.exceptions.SSLError: - return (dict(error=_('SSLError while trying to connect to {}').format(url)), status.HTTP_500_INTERNAL_SERVER_ERROR) + return (dict(error=_('SSLError while trying to connect to {}').format(url)), status.HTTP_502_BAD_GATEWAY) except requests.exceptions.Timeout: return (dict(error=_('Request to {} timed out.').format(url)), status.HTTP_504_GATEWAY_TIMEOUT) except requests.exceptions.RequestException as e: - return (dict(error=_('Unkown exception {} while trying to GET {}').format(e, url)), status.HTTP_500_INTERNAL_SERVER_ERROR) + return (dict(error=_('Unkown exception {} while trying to GET {}').format(e, url)), status.HTTP_502_BAD_GATEWAY) if res.status_code != 200: - return (dict(error=_('Failed to gather reports and maintenance plans from Insights API at URL {}. Server responded with {} status code and message {}').format(url, res.status_code, res.content)), status.HTTP_500_INTERNAL_SERVER_ERROR) + return (dict(error=_('Failed to gather reports and maintenance plans from Insights API at URL {}. Server responded with {} status code and message {}').format(url, res.status_code, res.content)), status.HTTP_502_BAD_GATEWAY) try: filtered_insights_content = filter_insights_api_response(res.json()) return (dict(insights_content=filtered_insights_content), status.HTTP_200_OK) except ValueError: - return (dict(error=_('Expected JSON response from Insights but instead got {}').format(res.content)), status.HTTP_500_INTERNAL_SERVER_ERROR) + return (dict(error=_('Expected JSON response from Insights but instead got {}').format(res.content)), status.HTTP_502_BAD_GATEWAY) def get(self, request, *args, **kwargs): host = self.get_object() diff --git a/awx/main/tests/unit/api/test_views.py b/awx/main/tests/unit/api/test_views.py index 8d7ccdfc59..15f1563a41 100644 --- a/awx/main/tests/unit/api/test_views.py +++ b/awx/main/tests/unit/api/test_views.py @@ -138,9 +138,9 @@ class TestHostInsights(): mocker.patch('awx.api.generics.GenericAPIView') @pytest.mark.parametrize("status_code, exception, error, message", [ - (500, requests.exceptions.SSLError, 'SSLError while trying to connect to https://myexample.com/whocares/me/', None,), + (502, requests.exceptions.SSLError, 'SSLError while trying to connect to https://myexample.com/whocares/me/', None,), (504, requests.exceptions.Timeout, 'Request to https://myexample.com/whocares/me/ timed out.', None,), - (500, requests.exceptions.RequestException, 'booo!', 'Unkown exception booo! while trying to GET https://myexample.com/whocares/me/'), + (502, requests.exceptions.RequestException, 'booo!', 'Unkown exception booo! while trying to GET https://myexample.com/whocares/me/'), ]) def test_get_insights_request_exception(self, patch_parent, mocker, status_code, exception, error, message): view = HostInsights() @@ -172,7 +172,7 @@ class TestHostInsights(): (msg, code) = view.get_insights('https://myexample.com/whocares/me/', 'ignore', 'ignore') assert msg['error'] == 'Expected JSON response from Insights but instead got booo!' - assert code == 500 + assert code == 502 #def test_get_not_insights_host(self, patch_parent, mocker, mock_response_new): #def test_get_not_insights_host(self, patch_parent, mocker):