Skip to content

Commit e96d0ff

Browse files
BUG: raise RuntimeError when Open-Elevation returns an error payload
The API answers {"code": "temporarily_unavailable", ...} without "results", which leaked a KeyError instead of the documented RuntimeError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDW574AQLHTSeBM9K172TX
1 parent a9c02dc commit e96d0ff

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎rocketpy/environment/fetchers/elevation_fetcher.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ def fetch_open_elevation(lat, lon):
3939
except (
4040
requests.exceptions.RequestException,
4141
requests.exceptions.JSONDecodeError,
42+
KeyError,
43+
IndexError,
4244
) as e:
4345
raise RuntimeError("Unable to reach Open-Elevation API servers.") from e

‎tests/unit/environment/test_fetchers.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,14 @@ def test_resolve_noaa_collection_path_rejects_unknown_model():
501501
"""Unknown shortcuts must fail with an actionable ValueError."""
502502
with pytest.raises(ValueError, match="Unknown NOAA model collection"):
503503
fetchers.resolve_noaa_collection_path("not-a-model")
504+
505+
506+
def test_fetch_open_elevation_error_payload_raises_runtime_error(monkeypatch):
507+
"""An error payload (no ``results``) must surface as the documented RuntimeError."""
508+
payload = {"code": "temporarily_unavailable", "error": "Retry shortly."}
509+
monkeypatch.setattr(
510+
fetchers.requests, "get", lambda *a, **k: _FakeResponse(payload)
511+
)
512+
monkeypatch.setattr("rocketpy.tools.time.sleep", lambda _: None)
513+
with pytest.raises(RuntimeError, match="Open-Elevation"):
514+
fetchers.fetch_open_elevation(48.858844, 2.294351)

0 commit comments

Comments
 (0)