Answers for "await and catch javascript"

17

async await catch error

async function f() {

  try {
    let response = await fetch('/no-user-here');
    let user = await response.json();
  } catch(err) {
    // catches errors both in fetch and response.json
    alert(err);
  }
}
Posted by: Guest on March-21-2020
-1

await and catch javascript

var response = await promisedFunction().catch((err) => { console.error(err); });
// response will be undefined if the promise is rejected
// this will work instead of using try...catch...
Posted by: Guest on May-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language