Firebase功能Promise Chain没有捕获错误

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

我正在使用Firebase功能来检测何时将Stripe Token添加到用户集合,然后创建Stripe用户并为该用户创建Subscription。

我遇到的问题是下面的代码中有一个错误,虽然我需要弄清楚那个错误是什么,Promise Chain似乎没有抓住实际的错误。所有注销的都是Function execution took 4375 ms, finished with status: 'connection error'

有谁知道为什么会这样。我可以让它记录错误的唯一方法是嵌套Promises。

exports.createStripeUser = functions.firestore
  // A Stripe Token is created in a user, therefore they have agreed to pay
  // Create a User in Stripe, and then attach the subscription to the Stripe customer
  .document('users/{userId}/stripe/{stripeCollectionId}')
  .onCreate((snap, context) => {
    const stripeToken = snap.data().stripeToken;
    let customer;
    return admin.auth().getUser(`${context.params.userId}`)
    .then(userObj => {
      const user = userObj.toJSON();
      return stripe.customers.create({
        email: user.email,
        source: stripeToken
      })
    })
    .then(cust => {
      customer = cust;
      return db.collection('users').doc(context.params.userId).collection('plan').doc(context.params.userId).get()
    })
    .then(plan => {
      return stripe.subscriptions.create({
        customer: customer.id,
        items: [{plan: plan.data().plan}]
      })
    })
    .catch(e => {
      console.log("ERRR", e)
      throw new functions.https.HttpsError('unknown', e.message, e);
    })
  })
javascript firebase google-cloud-functions
1个回答
0
投票

把你的街区包裹起来

try {

} 
catch (e) { 
// e holds the nested error message 
} 

阻止并在那里找到错误。

© www.soinside.com 2019 - 2024. All rights reserved.