Firebase功能现在超时

问题描述 投票:0回答:1

我读了关于FIR超时的其他SO帖子,其中一些是由于firebase-functionsfirebase-admin的更新。我更新到最新版本,甚至降级回原来的版本(git checkout)。

这些都没有奏效。

我收到任何FIR函数的Function execution took 60002 ms, finished with status: 'timeout'错误(请求在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功能UI也发生了变化(在控制台中;我认为有重大更新),或者我的语法跟不上节点6。

更新:

FIR功能再次开始工作,但我没有改变任何东西。案件结案。我希望这与我的付费计划订阅有关。

javascript firebase google-cloud-functions
1个回答
0
投票

您的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);
    })
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.