en.javascript.info/1-js/11-async/08-async-await/01-rewrite-async/task.md
hrodward 563d0a4556
Update task.md
Rephrase
2019-10-31 09:40:43 +01:00

438 B

Rewrite using async/await

Rewrite this example code from the chapter info:promise-chaining using async/await instead of .then/catch:

function loadJson(url) {
  return fetch(url)
    .then(response => {
      if (response.status == 200) {
        return response.json();
      } else {
        throw new Error(response.status);
      }
    })
}

loadJson('no-such-user.json') // (3)
  .catch(alert); // Error: 404