diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b59c8f4..a6d7c742 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,11 @@ Section Order: +### Fixed + +- Fail gracefully on `RequestError`, which can be thrown by `django-esi` when ESI is + unavailable, instead of crashing the task (Downtime, Endpoint down, etc.) + ### Changed - (Internal) Better type hinting diff --git a/sovtimer/providers.py b/sovtimer/providers.py index 85a2bbe2..66d44dd9 100644 --- a/sovtimer/providers.py +++ b/sovtimer/providers.py @@ -8,7 +8,7 @@ from typing import Any # Third Party -from aiopenapi3 import ContentTypeError +from aiopenapi3 import ContentTypeError, RequestError from httpx import Response # Alliance Auth @@ -107,7 +107,7 @@ def result( # pylint: disable=too-many-arguments, too-many-positional-arguments ) esi_result = None - except HTTPClientError as exc: + except (HTTPClientError, RequestError) as exc: logger.error(msg=f"Error while fetching data from ESI: {str(exc)}") esi_result = None diff --git a/sovtimer/tests/test_providers.py b/sovtimer/tests/test_providers.py index 531b664f..f9ba43aa 100644 --- a/sovtimer/tests/test_providers.py +++ b/sovtimer/tests/test_providers.py @@ -12,7 +12,7 @@ from unittest.mock import MagicMock, patch # Third Party -from aiopenapi3 import ContentTypeError +from aiopenapi3 import ContentTypeError, RequestError # Alliance Auth from esi.exceptions import HTTPClientError, HTTPNotModified @@ -139,6 +139,27 @@ def test_returns_none_when_http_client_error_occurs(self): self.assertIsNone(response) mock_operation.result.assert_called_once() + def test_returns_none_when_request_error_occurs(self): + """ + Test that an HTTPRequestError exception is raised correctly. + + :return: + :rtype: + """ + + mock_operation = MagicMock() + mock_operation.result.side_effect = RequestError( + operation=mock_operation, + request=MagicMock(), + data={}, + parameters={}, + ) + + response = ESIHandler.result(mock_operation) + + self.assertIsNone(response) + mock_operation.result.assert_called_once() + def test_passes_extra_parameters_to_operation(self): """ Test that extra parameters are passed correctly to the ESI operation.