Node.js 在节点JS中的Firebase函数HTTPS请求中报告错误的正确方法
我在node.js中实现了一个Firebase函数,可以通过浏览器(我使用postman进行测试)在HTTPS上直接调用:Node.js 在节点JS中的Firebase函数HTTPS请求中报告错误的正确方法,node.js,google-cloud-functions,Node.js,Google Cloud Functions,我在node.js中实现了一个Firebase函数,可以通过浏览器(我使用postman进行测试)在HTTPS上直接调用: exports.notifToAdmin = functions.https.onRequest((request, response) => { const title = request.query.title const body = request.query.body const badge = request.query.badge if
exports.notifToAdmin = functions.https.onRequest((request, response) => {
const title = request.query.title
const body = request.query.body
const badge = request.query.badge
if (typeof title === 'undefined') { return response.status(500).send("title missing") }
if (typeof body === 'undefined') { return response.status(500).send("body missing") }
if (typeof badge === 'undefined') { return response.status(500).send("badge missing") }
notifications.sendNotifToAdmin(title, body, badge)
.then(message => {
const ackString = fingerPrint(msg);
return response.send(ackString);
})
.catch(error => {
console.error(error);
return response.status(500).send(error);
});
});
- 我是否使用了正确的方法将错误发送回调用方(通过
)?在中,我看到了response.status(500).send(“…”)
的用法。所以我不确定我所做的是否是最理想的方式?我确实注意到文档说,抛出新错误(…)
//如果未捕获,将导致冷启动(链接到此抛出错误),我不想重新启动任何东西,只需向调用方报告错误
- 我知道onRequest结果应该是一个承诺,如果我更改代码并在
(这返回一个承诺),那么这与通知前面放置
。SendNotifToAdmin(…)返回值
(这将如何加在一起?)?那么,这也是一种回报吗返回响应。send(…)