何时需要对 async/await 进行异常捕获
何时需要对 async/await 进行异常捕获
try {
// TypeError: Cannot read properties of undefined (reading 'data')
// 就是当接口没有返回指定对象,而你又从 undefined 中解构的话,就会引发报错,就需要捕获,注意,这个请求拦截器应该是捕获不到的,因为这是解构出的错
const { test: { data } } = await axios.get('http://localhost:9999/one')
} catch (e) {
console.error(e)
}
这一路,灯火通明

浙公网安备 33010602011771号