ai-coding-minesIndexGitHub

Ignore the HTTP status and a 400 reads as "0 rows"

Write APIs

Symptom

Order query returned 0 rows. Judged "nothing unshipped" and moved on. In reality 9 unfulfilled orders were sitting there, 4 of them past deadline.

Cause

The query window was 40 days; the API's ceiling is under 32 days.

"endTime-startTime range should less than 32 day."

It was HTTP 400. But the code only counted the length of the data array, so len([]) == 0 → "0 rows."

Look only at the body and not the status code, and every 4xx turns into 0 rows.

Fix

Check the status code first in the query wrapper, and on non-2xx raise instead of returning 0. A function that returns the same value for "0 rows" and "query failed" will always deceive its caller.

Same mechanism, from a public geodata API

Raised a search-radius parameter to three times its ceiling (10,000 m). The API returned an error; the collector exited normally with "0 documents." Without reading the log it would have spun for hours.

When a parameter has a ceiling, don't raise the value; add call sites. Instead of growing one center's radius, tile: the center plus four points around it, then dedupe by title. There are two ways to widen coverage, and a ceiling leaves only the second.

A collector never treats 0 rows as a normal result. Log it as a warning. A real 0 costs a human one glance; a fake 0 has that warning as its only clue.