javascript - Firebase 函数现在超时
问题描述
我阅读了其他关于 FIR 超时的 SO 帖子,其中一些是由于更新firebase-functions
或firebase-admin
. 我更新到最新版本,甚至降级回原来的工作版本(git checkout)。
这些都不起作用。
我收到Function execution took 60002 ms, finished with status: 'timeout'
任何 FIR 函数的错误(而请求在 Postman 中工作)
示例代码:
exports.BSGetRequest = functions.https.onCall((url, context) => {
console.log(url);
const options = {
method: 'GET',
uri: url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'MY_PRIVATE_KEY'
},
json: true
};
return rp(options)
.then(function (response) {
console.log({ response });
return repos;
})
.catch(function (err) {
console.error({ err });
return err
});
});
我怀疑当 Firebase Functions UI 也发生变化(在控制台中;我认为有一个重大更新)或者我的语法跟不上 Node 6 时,它就开始发生了。
更新:
FIR 函数再次开始工作,但我没有改变任何东西。结案。我希望这与我的付费计划订阅有关。
解决方案
您的 UPDATED 错误消息可能会被抛出,因为response
它不是对象并且没有body
属性。
变量中可能有一些error
您没有检查的消息。
我已经通过一些注释和调试对您的代码进行了一些分解,这应该可以帮助您深入了解事情的真相。
该请求将超时,因为它正在抛出错误并且没有通过promise
.
exports.BSGetRequest = functions.https.onCall((url, context) => {
const options = {
url: url,
headers: {
'Content-Type' : 'application/json',
'Accept': 'application/json',
'Authorization': 'MY_PRIVATE_KEY'
},
json: true
};
return new Promise(function (fullfilled, rejected) {
request.get(options, function (error, response, body) {
const decoded = he.decode(JSON.stringify(response.body));
if (!error && response.statusCode >= 200 && response.statusCode <= 300) {
fullfilled(JSON.parse(decoded));
return;
}
// What's in `error`?
console.error({ error });
// I'm guessing this is where the error is - What's in `response` - Is there a `body`?
console.log({ response });
const responseErrorMessage = he.decode(JSON.stringify(response.body));
const responseError = new functions.https.HttpsError('invalid-argument', responseErrorMessage);
rejected(responseError);
})
});
});
编辑:尝试抛出错误信息;
exports.BSGetRequest = functions.https.onCall((url, context) => {
const options = {
url: url,
headers: {
'Content-Type' : 'application/json',
'Accept': 'application/json',
'Authorization': 'MY_PRIVATE_KEY'
},
json: true
};
return new Promise(function (fullfilled, rejected) {
request.get(options, function (error, response, body) {
const decoded = he.decode(JSON.stringify(response.body));
if (!error && response.statusCode >= 200 && response.statusCode <= 300) {
fullfilled(JSON.parse(decoded));
return;
}
// This should handle your error correctly.
if (error) {
const throwError = new functions.https.HttpsError('invalid-argument', error);
rejected(throwError);
return;
}
const responseErrorMessage = he.decode(JSON.stringify(response.body));
const responseError = new functions.https.HttpsError('invalid-argument', responseErrorMessage);
rejected(responseError);
})
});
});
推荐阅读
- wordpress - Woocommerce 订阅使用 REST API 处理更新
- c++ - 类模板参数的特化在 GCC、Clang 和 MSVC 中编译,但 GCC 选择了另一种特化
- c# - 如何在注册表页面上列出身份中的角色
- flutter - 导航到另一个屏幕时我丢失了流数据
- java - 如何从 xml java android 读取所有标签和值?
- jquery - 仅发送第一个输入值的输入字段数组
- regex - 如何排除前面字符与正则表达式中指定的字符不同的字符?
- visual-studio - 如何使用多个参数测试 Azure 函数
- android - 如何修复模拟器上的 apiAvailability.isGooglePlayServicesAvailable 行为不端
- mysql - PrestaShop 无缘无故地在 /tmp 中创建 #sql_ 文件