try / catch vs then / catch with axiom之间的区别

时间:2019-10-30 22:50:43

标签: promise callback async-await axios try-catch

试图了解这两者与axios库之间的区别。

function doSomething() {
  axios.get(url)
    .then((response) => process(response))
    .catch((error) => handle(error))
}

vs

async function doSomething() {
  try {
    const response = await axios.get(url);
    process(response);
  } catch(error) {
    handle(error);
  }
}

vs

async function doSomething() {
  return await axios.get(url);
}

vs

function doSomething() {
  return axios.get(url);
}

试图理解这一点,并为消费者编写axios调用的包装器。

谢谢。

0 个答案:

没有答案