Question Bank

Fetch API and Error Handling Quiz

Difficulty: Medium

Practice the small but easily-bungled `fetch` rituals: real error handling, Promise wrappers around timers, and `Promise.resolve` / `Promise.reject` for branching success states.

Question Bank
/

Fetch API and Error Handling Quiz

Fetch API and Error Handling Quiz

Practice the small but easily-bungled `fetch` rituals: real error handling, Promise wrappers around timers, and `Promise.resolve` / `Promise.reject` for branching success states.

Question Bank
Medium
JavaScript
4 questions
quiz
js-fetch-api
js-error-types
promises

501 views

12

Implement fetchData(url) that performs a fetch, throws on non-2xx responses, parses the body as JSON, and logs the data or error.

Examples

Example 1:

Input: fetchData('/api/items')
Output: logs the parsed JSON, or logs 'There was a problem with your fetch operation: ...' on failure.
Explanation: `fetch` only rejects on network errors; 4xx/5xx come back as resolved responses with `ok: false`, so you must check explicitly.