什么是尝试捕获真的抓到?在该场景中捕捉将被触发?
如果给定的请求:
try {
const response = await axios.get('someURL/api/apiEndpoint')
...(do something with response)
} catch(error) {
console.error(error);
...(Do something with error)
}
和后端代码:
app.get('/api/apiEndpoint', (req, res, next) => {
const notLoggedIn = () => {
return res.status(200).send({
error: 'Not logged in'
})
}
})
意志try-catch块捕获,有一个错误?
不,它会在catch块仅响应具有像503错误状态代码(内部服务器错误),400(坏请求)
在你的情况,你要发送200状态码,这样就不会进去抓
有关状态代码的更多信息,请 - https://httpstatuses.com/