Created
July 12, 2017 11:17
-
-
Save lethalbrains/e8dcb97b9ba36ddb53265be8562edf82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Current syntax | |
function fetchJson(url) { | |
return fetch(url) | |
.then(request => request.text()) | |
.then(text => { | |
return JSON.parse(text); | |
}) | |
.catch(error => { | |
console.log(`ERROR: ${error.stack}`); | |
}); | |
} | |
// New async functions | |
async function fetchJson(url) { | |
try { | |
let request = await fetch(url); | |
let text = await request.text(); | |
return JSON.parse(text); | |
} | |
catch (error) { | |
console.log(`ERROR: ${error.stack}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment