【发布时间】:2018-07-23 13:11:17
【问题描述】:
我正在使用 Firebase 函数来检测何时将 Stripe 令牌添加到用户集合中,然后创建 Stripe 用户并为该用户创建订阅。
我遇到的问题是下面的代码中有一个错误,虽然我需要弄清楚那个错误是什么,但 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