JSFiddle - React, Tailwind, and code Playground

by jfriend00

JavaScript

function myFetch(url) {
    return fetch(url).catch(function(err) {
       let myError = new Error("Fetch operation failed on " + url);
       myError.url = url;
       throw myError;
    });
}

const goodUrl = 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js';
const badUrl = 'https://ajax.googleapis77.com/ajax/libs/jquery/2.1.3/jquery.min.js';
Promise.all([
    myFetch(goodUrl),
    myFetch(badUrl), /* will fail */
    myFetch(goodUrl)
]).then(([response1, response2, response3]) => {
    console.log(response1);
    console.log(response2);
    console.log(response3);
}).catch((err) => {
    console.log(err);
    document.body.innerHTML = err.message;
});