Node.js Firebase云函数:在';捕捉';

Node.js Firebase云函数:在';捕捉';,node.js,firebase,promise,google-cloud-functions,axios,Node.js,Firebase,Promise,Google Cloud Functions,Axios,我正在使用Firebase云函数创建一个HTTP函数。 此函数的目的是执行POST并返回响应。 (我使用Axios来完成POST) 这是我的密码: exports.doHttpPost = functions.https.onRequest((request, response) => { axios.post(url, data, config) .then(response => { console.log(response);

我正在使用Firebase云函数创建一个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? <--
        });
});
exports.doHttpPost=functions.https.onRequest((请求,响应)=>{
post(url、数据、配置)
。然后(响应=>{
控制台日志(响应);
响应。状态(200)。发送(响应);
})
.catch(错误=>{
console.log(错误);

//-->我应该在这里写些什么来结束函数?Axios在错误对象中为您提供了
response
属性。因此,您应该能够以与成功流中相同的方式代理错误响应(未测试):


除了下面的@Teneff answer,您还可以观看Firebase官方视频:
exports.doHttpPost = functions.https.onRequest((request, response) => {
    axios.post(url, data, config)
        .catch(error => {
            response.status(error.response.status).send(error.response);
        });
});