promptdojo_

GET, status, JSON — the call AI makes 100 times a day — step 9 of 9

Checkpoint

One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.

Final drill. Below is a function fetch that simulates an API call — it returns a (status_code, body) tuple. Write a function safe_fetch that:

  • Calls fetch(user_id).
  • If the status is 200, returns body["name"].
  • For any other status, returns the string "error".

Then the script will call safe_fetch(7) and safe_fetch(404) and print both. Expected output:

maya
error

full-screen editor opens — close anytime to keep reading.