Node.js 处理axios request.post时出错
我们有一个axios方法,比如Node.js 处理axios request.post时出错,node.js,reactjs,express,axios,Node.js,Reactjs,Express,Axios,我们有一个axios方法,比如 export function callAcme(message) { const requestUrl = `/api/acme/message`; return { type: ACME_MESSAGE, promise: request.post(requestUrl, { data: message }) }; } 此方法映射到express router方法,该方法调用第三方API以获取一些数据 router.p
export function callAcme(message) {
const requestUrl = `/api/acme/message`;
return {
type: ACME_MESSAGE,
promise: request.post(requestUrl, {
data: message
})
};
}
此方法映射到express router方法,该方法调用第三方API以获取一些数据
router.post("/acme/message", (req, res) => {
const { data } = req.body;
const url = "third/party/url/action;
authenticateThirdparty({
user: req.user
}).then(userToken => request({
method: "post",
url,
data: body,
baseURL: url,
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "no-cache",
headers: {
Authorization: `Bearer ${userToken}`
}
})).then((response) => {
res.status(200).send(response.data);
}).catch((error) => {
res.status(error.status).send(error.data);
});
});
第三方调用是在try-catch
块中进行的。但是id第三方方法引发了一些错误,因此我们无法将错误发送回发起axios
调用的网页
例如,在调用
callAcme
的客户端中,将不会返回错误对象。对不起,但是您的callAcme
函数似乎是一个redux操作创建者。如果您正在使用redux,您必须使用类似于redux think
的方法来处理这些内容。是的,谢谢。刚开始为这个做减速器。无法将此标记为答案,抱歉。。。wasredux thunk
。是的,我是从第一条消息本身得到的,谢谢你。你用邮递员测试了端点了吗?如果出现错误,行为是什么?服务器挂起了吗?