Retrying an API request
`fetch_user(client, user_id, attempts=3)` fetches a user through a client with a
`get(path)` method. The response has `status_code` and `json()`.
Rules:
- `200` — return `response.json()`;
- `404` — raise `ApiError` immediately, no retries;
- any other status — retry, no more than `attempts` calls in total;
- when the attempts run out — raise `ApiError`.
Write tests with a fake client: no network calls. Cover success, retry, `404`
without a retry, and exhausted attempts.
The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.
Log in and askHint 1
How many times should `get()` be called in each scenario? Start with the
question: what makes `404` different from `500` for the client?