js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Homework * convert using async await instead of promise then catch #459

Closed odv closed 4 years ago

odv commented 4 years ago
function loadJson(url) {
  return fetch(url)
    .then(response => {
      if (response.status == 200) {
        return response.json();
      } else {
        throw new Error(response.status);
      }
    })
}
RazvanBugoi commented 4 years ago
async function loadJson(url) {
    let response = await fetch(url);
    if (response.status == 200) {
        return response.json();
} else {
    throw new Error(response.status);
}
}