http and apis — making the call7 / 9
status codes and error handling — what ai's api calls do when the wire blinks
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)
The break is on lines 4, 5 — but read the whole snippet first.
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _