Fetch, promises, and async/await
Await requests and distinguish network completion from HTTP success.
- Difficulty
- beginner
- Time
- 45 minutes
- Last verified
- 9/21/2026
What you will build
Await requests and distinguish network completion from HTTP success.
Understand the idea first
Await requests and distinguish network completion from HTTP success.
Build it step by step
async function loadData(url) {
const response = await fetch(url);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return response.json();
}- Open the previous project and record its result.
- Type the example and complete: Call a public test API and print status, Content-Type, and parsed data.
- Change one input, predict, then verify.
- Create and repair: Fetch does not necessarily reject on 404; check response.ok.
Read the important lines
- Await requests and distinguish network completion from HTTP success.
- Read input, processing, and output separately.
- Verify another input and an edge case.
Common mistakes and what to check
| Symptom | What to check |
|---|---|
| Unexpected result | Fetch does not necessarily reject on 404; check response.ok. |
| Nothing changes | Save, verify paths, and read the first relevant Console error. |
Practice without copying
Call a public test API and print status, Content-Type, and parsed data.
Check the answer after you try
Rebuild and explain the decisions. Check: Fetch does not necessarily reject on 404; check response.ok.
Completion check
- I produced the required visible result
- I can explain the input, processing, and output
- I tested normal, edge, and failure cases