【问题标题】:Ignoring exception from a finished function忽略已完成函数的异常
【发布时间】:2019-07-11 06:55:42
【问题描述】:

执行此函数时,我不断收到此错误。

忽略已完成函数的异常

我错过了什么?

exports = module.exports =  functions.database.ref('/cards/{userId}/{id}')
    .onCreate((snap, context) => {

        const token = snap.val().token;

        const userId = context.params.userId;

        const stripeRef = admin.database().ref('/stripe').child(userId);

        return stripeRef.once('value').then(function(snapshot) {

            let accountId =  snapshot.val().accountId;

            return stripe.accounts.createExternalAccount(
                accountId,
                { external_account: token },
                function(err, card) {
                    snap.ref.child('cardId').set(card.id);
                });
         });
    });

【问题讨论】:

  • createExternalAccount 实际上是否返回了一个承诺?我怀疑不是,因为您依赖于接收回调而不是接收来自承诺的结果。如果它没有返回一个 Promise,那么你的最后一个 return 没有做任何有用的事情,并且函数在收到回调之前终止。
  • 谢谢,能发个例子吗?
  • 删除最后一个返回后我得到了同样的错误
  • 删除该返回不会帮助您做正确的事情,即返回一个仅在函数中的所有异步工作完成后才解析的承诺。
  • 我还是不明白!我是一名 iOS 开发者。我是新手。您介意给我看一些代码或参考吗?

标签: node.js firebase google-cloud-functions stripe-payments


【解决方案1】:

使用 try 和 catch 手动记录错误,例如

try {
  //code goes here
}
catch(error) {
  console.log(error)
}

【讨论】:

    猜你喜欢
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    相关资源
    最近更新 更多