[英]No expected error with axios and express router
我正在使用说明从我的 API 请求第三方 API。 但是,我收到了一份空文件作为退货。
module.exports = app => {
const servicesToll = (req, res) => {
var obj
try {
console.log("'/test' call");
axios.post('MyUrl')
.then(res => {
obj = res.data
console.log(obj)
res.status(200).json(res.data)
})
.catch(err => res.send(err));
} catch (err) {
console.error("GG", err);
console.log("I get error")
}
}
console.log("I pass")
return { servicesToll }
}
这样,我不会让控制台返回消息:“我通过”,也没有预期的对象。
值得一提的是,console.log (obj) 返回的正是我期望收到的。
app.route('/api')
.get(app.api.modulos.servicesToll)
控制台打印:
“/测试”调用
{ access_token: 'YFns9SsMILak0aE9dRbqX0aw5UlFq9', expires_in: 86400, token_type: 'Bearer', scope: '', refresh_token: 'yTAY78b08Cz15brNK925IheNf7phwX
修复方法是:
.then(response => {
// obj = res.data
console.log(response.data)
res.status(200).json(response.data)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.