2 回答
TA贡献1817条经验 获得超6个赞
如果您不想在捕获错误后执行代码,那么您应该这样做:
app.get('/submit/:imei', async function (req, res) {
//configure
res.setHeader('Content-Type', 'application/json');
MyUserAgent = UserAgent.getRandom();
axios.defaults.withCredentials = true;
try {
const model_info = await getModelInfo(req.params.imei);
console.log('This will not get called if there is an error in getModelInfo');
res.send({ success: true });
} catch(error) {
if(error.response && error.response.status === 406) {
return res.send({
'success': false,
'reason': 'exceeded_daily_attempts'
});
}
}
});
或者,您可以在通话then后使用,只有在不拒绝getModelInfo时才会调用该代码。getModelInfo
TA贡献1785条经验 获得超4个赞
它也应该有一个成功块。
app.get('/submit/:imei', async function (req, res) {
//configure
res.setHeader('Content-Type', 'application/json');
MyUserAgent = UserAgent.getRandom();
axios.defaults.withCredentials = true;
const model_info = await getModelInfo(req.params.imei)
.then(function (response) {
return res.send(JSON.stringify({
'success': true,
'res': response
}));
})
.catch(function (error) {
if (error.response && error.response.status === 406) {
return res.send(JSON.stringify({
'success': false,
'reason': 'exceeded_daily_attempts'
}));
}
});
//it will console log
console.log('This still gets called even after 406 error!');
});
添加回答
举报