Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Section Order:

<!-- Your changes go here -->

### 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
Expand Down
4 changes: 2 additions & 2 deletions sovtimer/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion sovtimer/tests/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Loading