【发布时间】:2019-07-03 09:29:35
【问题描述】:
我正在使用 Firebase Cloud Function 创建一个 HTTP 函数。 此函数的目的是执行 POST 并返回响应。 (我使用 Axios 来进行 POST)
这是我的代码:
exports.doHttpPost = functions.https.onRequest((request, response) => {
axios.post(url, data, config)
.then(response => {
console.log(response);
response.status(200).send(response);
})
.catch(error => {
console.log(error);
// --> What should I write here to end the function? <--
});
});
我的问题是:如果“axios.post”失败,我该如何结束函数? 我用“response.status(200).send(response)”正确地完成了“then”。但我不知道如何完成'catch'。
【问题讨论】:
-
除了下面的@Teneff 回答之外,您还可以观看这个 Firebase 官方视频:youtube.com/watch?v=7IkUgCLr5oA
标签: node.js firebase promise google-cloud-functions axios