Javascript Firebase承诺发行——”;超过最大调用堆栈大小;

Javascript Firebase承诺发行——”;超过最大调用堆栈大小;,javascript,function,firebase,google-cloud-functions,callable,Javascript,Function,Firebase,Google Cloud Functions,Callable,我对可调用函数有问题。以下是我的Firebase函数: const functions = require('firebase-functions'); const admin = require('firebase-admin'); const request = require('request-promise'); admin.initializeApp(functions.config().firebase); exports.phoneAuthRequest = functions

我对
可调用函数有问题。以下是我的Firebase函数:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const request = require('request-promise');

admin.initializeApp(functions.config().firebase);

exports.phoneAuthRequest = functions.https.onCall((data, context) => {
  // Message text passed from the client.
  const text = data.text;

  // Authentication / user information is automatically added to the request.
  const uid = context.auth.uid;
  const phone = context.auth.token.phone_number;

  const url = "https://api.authy.com/protected/json/phones/verification/start?api_key=<key here>&via=sms&country_code=1&phone_number=" + phone;
  const httpReq = {
    uri: url,
    method: 'POST',
    json: true,
    resolveWithFullResponse: true
  };

  return new Promise((resolve, reject) => {
    request(httpReq).then((response) => {
      // Twillio request returned with success
      console.log("response: " + JSON.stringify(response));
      return resolve(response);
    }).catch(function(error) {
      console.log("error: " + JSON.stringify(error));
      return reject(error);
    });  
  });
});
当然,客户的反应是:

{"code":"internal"}
当我阅读类似的文章时,我的建议是序列化承诺,我不确定我是否完全理解如何做,或者,将异步调用(本例中为请求)包装在新承诺中,这正是我在这里所做的,但它仍然不起作用

如果你要回答这个问题,你能通过展示一个代码示例来具体说明建议的解决方案吗


提前感谢…

尝试删除客户端并通过curl调用Firebase函数


好的,我解决了这个问题,我的头撞到了墙上。代码如下:

exports.phoneAuthRequest = functions.https.onCall((data, context) => {
  // Example of using context to obtain the user information about the calling user
  const uid = context.auth.uid;
  // Example of obtaining a paramter that was passed by the calling function
  const phone = data.phone;
  const e164 = "+1" + phone;

  httpReq = ...

  // Example of a return if you have not yet made a call to an asynchonous function.
  return ({'status': 'success'});

  // Here is an example of a nested set of asynchonous calls and how to return from them.
  return admin.auth().updateUser(uid, {'phoneNumber': e164}).then(function(userRecord) {
    // the Phone Number was updated
    return request(httpReq).then((response) => {
      var updates = {};
      updates['/users/' + uid + "/centralVerified"] = false;
      return database.ref().update(updates).then(function(rslt) {
        return Promise.resolve({'status': 'success');
      }).catch(function(error) {
        return Promise.reject({'status': 'failed'});
      });
    }).catch(function(error) {
      return Promise.reject({'status': 'failed'});
    });
  }).catch(function(error) {
    return Promise.reject({'status': 'failed'});
  });
});
请注意,在上面有两种不同的方法可以从可调用函数返回。如果没有进行任何异步调用,则可以简单地返回值,但如果调用了异步函数,则必须返回承诺。如果要在调用例程中查找拒绝或解析,则假定返回的值为解析


我希望这能帮助其他人。。。祝你好运

是否有更多关于错误的信息?错误通常包括一些关于错误发生位置的跟踪-哪个
console.log
输出错误?我已经更新了主线程以包含完整的错误。毫无疑问,promise函数在某些容量中循环,这可能是由于编码错误造成的。我只需要了解我做错了什么,以及如何修复它。错误是在客户端还是服务器端?错误在服务器端。
response:
是否已记录?恕我直言,可调用函数没有可调用的端点,并且依赖于客户端上下文。在这种情况下,不可能删除客户端。有多个消息来源不这么说。[ () [ ()
{"code":"internal"}
exports.phoneAuthRequest = functions.https.onCall((data, context) => {
  // Example of using context to obtain the user information about the calling user
  const uid = context.auth.uid;
  // Example of obtaining a paramter that was passed by the calling function
  const phone = data.phone;
  const e164 = "+1" + phone;

  httpReq = ...

  // Example of a return if you have not yet made a call to an asynchonous function.
  return ({'status': 'success'});

  // Here is an example of a nested set of asynchonous calls and how to return from them.
  return admin.auth().updateUser(uid, {'phoneNumber': e164}).then(function(userRecord) {
    // the Phone Number was updated
    return request(httpReq).then((response) => {
      var updates = {};
      updates['/users/' + uid + "/centralVerified"] = false;
      return database.ref().update(updates).then(function(rslt) {
        return Promise.resolve({'status': 'success');
      }).catch(function(error) {
        return Promise.reject({'status': 'failed'});
      });
    }).catch(function(error) {
      return Promise.reject({'status': 'failed'});
    });
  }).catch(function(error) {
    return Promise.reject({'status': 'failed'});
  });
});