Since you're just returning the error after catching it, it'll no longer reach the catch
block inside useEffect
.
Just throw the error in the catch block:
const postStuff = async() => {
try {
const res = 'bla';
throw new Error();
return res;
} catch (err) {
throw new Error();
}
};
postStuff().then(res => console.log('then', res))
.catch(err => console.log('catch', err))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…