en.javascript.info/6-async/05-async-await/01-rewrite-async/task.md
Ilya Kantor 455d300d8d renames
2017-05-25 11:56:32 +03:00

440 B

Rewrite using async/await

Rewrite the one of examples 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