最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

火力地堡云功能:在“捕获”结束的HTTP功能

运维笔记admin11浏览0评论

火力地堡云功能:在“捕获”结束的HTTP功能

火力地堡云功能:在“捕获”结束的HTTP功能

我使用的火力地堡云函数创建一个HTTP功能。该功能的目的是做一个POST并返回响应。 (我用爱可信为了做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)。发送(响应)”。但我不知道如何完成“抓”。

回答如下:

爱可信为您提供错误对象response属性。所以,你应该能够代理错误响应相同的方式,在成功流(未测试):

exports.doHttpPost = functions.https.onRequest((request, response) => {
    axios.post(url, data, config)
        .catch(error => {
            response.status(error.response.status).send(error.response);
        });
});
发布评论

评论列表(0)

  1. 暂无评论