Commit 3651f23
fix(errors): consistent error-status gateway + drop NWIS-flavored 413/414 leak
A /code-review (max) of the unified error path surfaced these:
- waterdata `_raise_for_non_200` guarded only `status == 200`, so a 2xx-non-200
or 3xx was routed through `error_for_status` and raised as a fatal ClientError
on a SUCCESS. Match the legacy `_raise_for_status`: guard `status < 400`.
(Latent today -- the OGC API paginates with 200s -- but the two gateways now
agree.)
- `_raise_for_status` special-cased 413/414 to `_url_too_long_error`, whose
message is NWIS-specific ("use fewer sites", an `nwis.get_record()` example).
nadp/streamstats (no sites) now route through this helper, so a 413/414 on a
streamstats download would emit nonsensical NWIS guidance -- and 413/414 was
mapped in two places. Drop the special-case: the factory owns 413/414 ->
URLTooLong with a generic message; the NWIS prose stays only on query()'s
client-side InvalidURL path (the common too-long-URL trigger).
- Status-first message ("HTTP {status} {reason}") so a non-standard status with
an empty reason_phrase (520/599 WAF codes) no longer leaves a stray leading
space.
- Extend `test_retryable_taxonomy` to pin that a typed waterdata 4xx
(BadRequestError/ClientError, ValueError-based) is fatal -- never retried --
closing a regression-guard gap (only a bare RuntimeError was covered).
- Fix a stale ratings.py comment that called the typed errors "all RuntimeError
subclasses" (4xx is now ClientError/BadRequestError; the `except` already
catches ValueError, so the skip-bad-feature behavior is intact).
ruff + mypy --strict clean; 483 passed / 2 skipped.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 426b82f commit 3651f23
5 files changed
Lines changed: 17 additions & 12 deletions
File tree
- dataretrieval
- waterdata
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | | - | |
297 | | - | |
| 296 | + | |
298 | 297 | | |
299 | 298 | | |
300 | 299 | | |
301 | 300 | | |
302 | | - | |
303 | | - | |
304 | 301 | | |
305 | | - | |
| 302 | + | |
| 303 | + | |
306 | 304 | | |
307 | 305 | | |
308 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
554 | | - | |
| 554 | + | |
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1603 | 1603 | | |
1604 | 1604 | | |
1605 | 1605 | | |
| 1606 | + | |
| 1607 | + | |
1606 | 1608 | | |
1607 | 1609 | | |
1608 | 1610 | | |
1609 | 1611 | | |
1610 | 1612 | | |
1611 | 1613 | | |
1612 | | - | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
1613 | 1619 | | |
1614 | 1620 | | |
1615 | 1621 | | |
| |||
0 commit comments