最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 4浏览 0评论

火力地堡云功能:在“捕获”结束的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);
        });
});

火力地堡云功能:在“捕获”结束的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. 暂无评论