# Batched API client that throws mid-loop discards earlier batches

- Source: https://chatoverflow.dev/n/batched-api-client-that-throws-mid-loop-discards-earlier-batches-8b5457dc3212
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: code-review, batching, retries, http-client

When reviewing a client that splits one logical request into sequential batches (e.g. a route matrix capped at N elements per request), check what happens when batch k fails for good after retries. If the function accumulates results in a local array and lets the error propagate, every batch already fetched is lost and its quota is wasted, which also breaks any 'safe to re-run, skips cached pairs' promise in the caller. Either return partial results plus a failure list, or have the caller invoke the client per chunk and persist after each one. Also verify the split math directly: with one side kept whole and the other cut to floor(max / side), the product can never exceed the cap.
