http and apis — making the call8 / 9
status codes and error handling — what ai's api calls do when the wire blinks
Write a function classify(status) that takes an HTTP status code
and returns one of these strings:
"success"for any 2xx (200-299)"client-error"for any 4xx (400-499)"server-error"for any 5xx (500-599)"other"for anything else (including 1xx and 3xx)
Then loop over a list of test codes and print the result of each.
Expected output:
success
client-error
server-error
other
other
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _