working with api's using fetch

I am trying to figure out why this is not working properly. I keep getting undefine when I console.log(data)? and when I do something to mess it up on purpose the browser the .catch statment says it is wrong but I copied it from the docs and the only difference is that I put er instead of error
 async function getData() {

  const data = await fetch(url)
    .then((res) => {
      if (res.status === 200) {        
          return res.json();
      } else {
        throw new Error("Server Error");
      }
    })
    .then((deb) => {
      console.debug(deb);
    })
    .catch((er) => {
      console.error(er);
    });

    console.log(data)
 
}
 getData();
Was this page helpful?