javascript - Firebase 函数承诺链未捕获错误
问题描述
我正在使用 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);
})
})
解决方案
将你的块包裹在一个
try {
}
catch (e) {
// e holds the nested error message
}
阻止并在那里找到错误。
推荐阅读
- .net - 将 Azure AD B2C 与机器人一起使用
- ios - 使用枚举和泛型快速扩展类的 Where 子句
- asp.net - 在 Asp.Net 中单击 GridView 中的添加按钮时,如何在下拉列表中删除先前选定的项目
- wpf - 如何确保 ListView 显示完整的项目
- android - 我怎样才能打开调试?ADB 如果我的手机被锁定并且我忘记了 PIN
- javascript - JavaScript 文本替换
- python - Python程序随机挂断
- python - python中大数的素数分解
- testing - 我可以在使用 nightwatch 的文件上传中使用 setValue 中的链接吗
- google-apps-script - 如何在 App Script 中将数据透视表值表示为列总数的百分比?