User-reported: manual food logging search shows "no results" when it should show the closest result.
frontend/src/components/FoodSearchInput.jsx (~L437-465, ~L607): the catch swallows every error (404/5xx/network/CORS) into setResults([]); showDropdown stays true from an earlier search, so the "No foods found. Try a different search term" branch renders for failures too. No AbortController/request-id, so a slow older response can overwrite the current query's results.
Backend: supabase/functions/search-food/index.ts (~L73-77) turns a USDA 429 / DEMO_KEY rate limit into a generic 500 (falls back to DEMO_KEY when USDA_API_KEY unset, ~L21). Same in food-details/index.ts (~L17).
Fix:
- Add an
error state; on failure show "Search unavailable, try again" (distinct from empty results). Show "No foods found" only after a 200 with empty foods.
- Ignore stale responses (AbortController via axios
signal, or query-id ref).
- In
search-food and food-details, map USDA 429 → 503 with detail: "Food database rate-limited, try again shortly"; log a warning when falling back to DEMO_KEY.
- Existing FoodSearchInput tests must pass; add tests for error state and stale-response guard.
User-reported: manual food logging search shows "no results" when it should show the closest result.
frontend/src/components/FoodSearchInput.jsx(~L437-465, ~L607): thecatchswallows every error (404/5xx/network/CORS) intosetResults([]);showDropdownstays true from an earlier search, so the "No foods found. Try a different search term" branch renders for failures too. No AbortController/request-id, so a slow older response can overwrite the current query's results.Backend:
supabase/functions/search-food/index.ts(~L73-77) turns a USDA 429 / DEMO_KEY rate limit into a generic 500 (falls back toDEMO_KEYwhenUSDA_API_KEYunset, ~L21). Same infood-details/index.ts(~L17).Fix:
errorstate; on failure show "Search unavailable, try again" (distinct from empty results). Show "No foods found" only after a 200 with emptyfoods.signal, or query-id ref).search-foodandfood-details, map USDA 429 → 503 withdetail: "Food database rate-limited, try again shortly"; log a warning when falling back toDEMO_KEY.