Back to the lesson

Fault-tolerant fetch with JSON

Improve the solution of the previous task Fault-tolerant Promise.all. Now we need not just to call fetch, but to load the JSON objects from given URLs.

Here’s the example code to do that:

let urls = [

// make fetch requests
Promise.all( => fetch(url)))
  // map each response to response.json()
  .then(responses => Promise.all( => r.json())
  // show name of each user
  .then(users => {  // (*)
    for(let user of users) {

The problem is that if any of requests fails, then Promise.all rejects with the error, and we loose results of all the other requests. So the code above is not fault-tolerant, just like the one in the previous task.

Modify the code so that the array in the line (*) would include parsed JSON for successful requests and error for errored ones.

Please note that the error may occur both in fetch (if the network request fails) and in response.json() (if the response is invalid JSON). In both cases the error should become a member of the results object.

The sandbox has both of these cases.

Open the sandbox for the task.