Skip to content

Commit 6f77da1

Browse files
committed
don't retry time series retrieval on 404 errors
1 parent c0ee334 commit 6f77da1

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

cwms/timeseries/timeseries.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ def _call_with_retry(fn: Any, *args: Any, attempts: int = _CHUNK_ATTEMPTS) -> An
166166
try:
167167
return fn(*args)
168168
except Exception as e:
169+
status_code = getattr(getattr(e, "response", None), "status_code", None)
170+
if status_code == 404:
171+
raise
169172
if i == attempts - 1:
170173
raise
171174
logging.warning(f"chunk attempt {i + 1}/{attempts} failed: {e}")

tests/mock/timeseries/timeseries_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,27 @@ def test_get_timeseries_paging(requests_mock):
251251
assert data.df.shape == (30, 3)
252252

253253

254+
def test_call_with_retry_does_not_retry_404():
255+
class ResponseStub:
256+
url = "https://mockwebserver.cwms.gov/timeseries"
257+
status_code = 404
258+
reason = "Not Found"
259+
content = b""
260+
261+
call_count = 0
262+
263+
def failing_call():
264+
nonlocal call_count
265+
call_count += 1
266+
raise cwms.api.ApiError(ResponseStub())
267+
268+
with pytest.raises(cwms.api.ApiError) as exc_info:
269+
timeseries._call_with_retry(failing_call)
270+
271+
assert exc_info.value.response.status_code == 404
272+
assert call_count == 1
273+
274+
254275
def test_get_timeseries_group_default(requests_mock):
255276
group_id = "USGS TS Data Acquisition"
256277
category_id = "Data Acquisition"

0 commit comments

Comments
 (0)