Commit 2afd2d7
refactor(errors): introduce DataRetrievalError as a unified request-error root
An HTTP failure surfaced as a different exception type depending on which
module made the request:
- legacy query() (wqp, nwis, ngwmn, nldi): ValueError, or NoSitesError(Exception)
- waterdata: RateLimited / ServiceUnavailable (RuntimeError),
RequestTooLarge (ValueError), ChunkInterrupted (RuntimeError)
- nadp / streamstats: bare httpx.HTTPStatusError
so no single `except` clause could catch "any dataretrieval request failure."
Add a shared base class, dataretrieval.utils.DataRetrievalError, and root the
existing exceptions on it. Unification is at the root only -- each exception
keeps the built-in type it has always raised, so the change is backward
compatible:
- New typed errors for the legacy query() path -- BadRequestError (400),
NotFoundError (404), RequestTooLargeError (414), ServiceUnavailableError
(5xx) -- each subclassing (DataRetrievalError, ValueError). Messages and the
set of statuses query() raises on are unchanged, and every type is still a
ValueError, so existing `except ValueError` handlers keep working.
- Consolidate query()'s inline status-code ladder into a reusable
_raise_for_status() helper.
- NoSitesError now subclasses DataRetrievalError (was Exception).
- waterdata's RateLimited / ServiceUnavailable / RequestTooLarge /
ChunkInterrupted gain DataRetrievalError as an additional base (additive --
they remain RuntimeError / ValueError, so the chunker's isinstance
classification and all existing handlers are unaffected).
Callers can now write `except dataretrieval.DataRetrievalError` to handle a
failure from any module while keeping the historical built-in types.
Out of scope (follow-ups): nadp/streamstats still raise httpx.HTTPStatusError;
nldi's manual non-200 ValueError and nwis._parse_json_or_raise's HTML-detection
ValueError are not yet rooted; waterdata's _raise_for_non_200 catch-all for
non-retryable 4xx stays a bare RuntimeError (load-bearing for the chunker's
fatal-vs-resumable classifier).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 473a07c commit 2afd2d7
3 files changed
Lines changed: 141 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
274 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
275 | 312 | | |
276 | 313 | | |
277 | 314 | | |
278 | 315 | | |
279 | 316 | | |
280 | 317 | | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
281 | 346 | | |
282 | 347 | | |
283 | 348 | | |
| |||
321 | 386 | | |
322 | 387 | | |
323 | 388 | | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
| 389 | + | |
340 | 390 | | |
341 | 391 | | |
342 | 392 | | |
343 | 393 | | |
344 | 394 | | |
345 | 395 | | |
346 | 396 | | |
347 | | - | |
| 397 | + | |
348 | 398 | | |
349 | 399 | | |
350 | 400 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
383 | 383 | | |
384 | 384 | | |
385 | 385 | | |
386 | | - | |
| 386 | + | |
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
| |||
435 | 435 | | |
436 | 436 | | |
437 | 437 | | |
438 | | - | |
| 438 | + | |
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
| |||
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
449 | | - | |
| 449 | + | |
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 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 | + | |
45 | 113 | | |
46 | 114 | | |
47 | 115 | | |
| |||
0 commit comments