en.javascript.info/1-js/11-async/08-async-await/01-rewrite-async/task.md
2019-03-09 17:24:12 +03:00

20 lines
440 B
Markdown

# Rewrite using async/await
Rewrite the one of examples from the chapter <info:promise-chaining> using `async/await` instead of `.then/catch`:
```js run
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
```