[英]Why "RangeError: Invalid status code: 0", firebase functions
With the following functions called as http request:使用以下函数称为 http 请求:
exports.newID = functions.https.onRequest(async (req, res) => {
let citiesRef = fireStore.collection('system').doc('uid_counter');
let snapshot = await citiesRef.get();
let counter = snapshot.get('counter');
console.log('current counter = ', counter);
res.status(200).send(counter);
The firebase functions console.log indicate that counter can be gotten well, but response gets an error: firebase 函数 console.log 表明计数器可以得到很好的,但响应得到一个错误:
I have no idea why I've gotten "RangeError: Invalid status code: 0" despite I've specified status(200) .尽管我已经指定了status(200) ,但我不知道为什么我得到了 "RangeError: Invalid status code: 0" 。 Thank you for your suggestions.谢谢你的建议。
The Express documentation for res.send([body])
states that res.send([body])
的 Express文档指出
The body parameter can be a Buffer object, a String, an object, or an Array. body 参数可以是一个 Buffer 对象、一个字符串、一个对象或一个数组。
So sending a Number is most probably the cause of your problem.因此,发送号码很可能是您出现问题的原因。
You could send the counter
value as an object, as follows:您可以将counter
值作为对象发送,如下所示:
res.status(200).send({ counter: counter});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.