en.javascript.info/1-js/11-async/08-async-await/01-rewrite-async/task.md
Violet Bora Lee e85e48f8d0 minor fixes
2020-01-27 15:24:23 +09:00

431 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')
  .catch(alert); // Error: 404