Commit 13b9032
Surface real failures in paginated waterdata responses
Two bugs in _walk_pages (and the parallel get_stats_data pagination
loop) caused silent or misleading failures when a paginated request was
interrupted mid-walk:
1. The except handler called _error_body(resp) — but when
client.request() itself raised (ConnectionError, Timeout, etc.),
`resp` still pointed at the *previous successful page*. The
"incomplete" log message therefore described the wrong request, and
on a non-JSON 200 body would itself raise inside resp.json() and
bury the original failure.
2. No status-code check was performed on paginated responses. The
initial request guards `if resp.status_code != 200`, but the loop
doesn't. A 5xx body that didn't include "numberReturned" was
silently turned into an empty DataFrame by _get_resp_data, the
`next` link wasn't found, and the loop quietly exited — handing the
user truncated data with no error logged anywhere. This affects
every paginated waterdata getter (get_daily, get_continuous,
get_monitoring_locations, …).
Fix:
- Guard the loop body with `if resp.status_code != 200: raise
RuntimeError(_error_body(resp))`, mirroring the initial request.
- Capture the exception with `as e` and log `e` instead of touching the
stale `resp`. Same change in get_stats_data.
Behavior preserved: on failure the loop still logs and returns
whatever pages were collected ("best effort"). The change is purely to
make the failure observable and the log message accurate.
Two new tests cover (a) network-exception mid-pagination and (b) 5xx
mid-pagination, asserting that the actual failure surfaces in the
error log.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 18f831f commit 13b9032
3 files changed
Lines changed: 104 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
638 | 643 | | |
639 | 644 | | |
640 | | - | |
641 | | - | |
642 | | - | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
643 | 650 | | |
644 | 651 | | |
645 | 652 | | |
| |||
1099 | 1106 | | |
1100 | 1107 | | |
1101 | 1108 | | |
| 1109 | + | |
| 1110 | + | |
1102 | 1111 | | |
1103 | 1112 | | |
1104 | 1113 | | |
1105 | | - | |
1106 | | - | |
1107 | | - | |
| 1114 | + | |
| 1115 | + | |
1108 | 1116 | | |
1109 | | - | |
| 1117 | + | |
1110 | 1118 | | |
1111 | 1119 | | |
1112 | 1120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
89 | 176 | | |
90 | 177 | | |
91 | 178 | | |
| |||
0 commit comments