Status codes and error handling — what AI's API calls do when the wire blinks — step 7 of 9
AI wrote a retry helper that re-tries on any non-2xx status. That's wrong — 4xx errors mean the request itself is broken, and retrying with the same payload just hammers the API. Only 5xx errors are retry-worthy.
Fix the condition on line 4 so the function only retries when the
status is in the 5xx family. For 4xx, it should return immediately
with the string "client error".
The helper makes up to 3 attempts. With three 4xx responses queued, expected output is:
client error
(one attempt, no retries)
AI wrote a retry helper that re-tries on any non-2xx status. That's wrong — 4xx errors mean the request itself is broken, and retrying with the same payload just hammers the API. Only 5xx errors are retry-worthy.
Fix the condition on line 4 so the function only retries when the
status is in the 5xx family. For 4xx, it should return immediately
with the string "client error".
The helper makes up to 3 attempts. With three 4xx responses queued, expected output is:
client error
(one attempt, no retries)
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.