node.js - 函数返回未定义、预期的 Promise 或值 - NodeJS
问题描述
我有一个角度应用程序,它使用 firestore 作为数据库和谷歌云功能来处理后端。当我运行我的应用程序并单击付款以调用Stripe API时,我在云功能的日志中收到以下消息。
函数返回未定义的、预期的 Promise 或值
我一直在阅读几个 stackoverflow 问题,他们谈论我返回 Promise 中的任何内容,.then()
但我一直收到同样的错误。好消息是实际值可以毫无问题地存储在 Firestore 中,因此它似乎更像是警告而不是错误,因为没有任何问题。
我错过了什么?
exports.stripeCharges = functions.firestore
.document("/payments/users/TAMO/{paymentId}")
.onWrite((event, context) => {
const payment = event.after.data();
const paymentId = context.params.paymentId;
if (!payment || payment.charge) return;
return admin
.firestore()
.doc(`/payments/users/TAMO/${paymentId}`)
.get()
.then(snapshot => {
return snapshot.data();
})
.then(customer => {
const amount = payment.amount * 100;
const idempotency_key = paymentId;
const source = payment.token.id;
const currency = "usd";
const description = "Test Charge";
const charges = {
amount,
currency,
description,
source
};
return stripe.charges.create(charges, { idempotency_key });
})
.then(charges => {
return admin
.firestore()
.doc(`/payments/users/TAMO/${paymentId}`)
.set(
{
charge: charges
},
{
merge: true
}
);
});
});
解决方案
我通过执行以下操作解决了此警告:
if (!payment || payment.charge) return null;
上面的行检查付款是否存在或是否已经收费
推荐阅读
- django-rest-framework - 身份验证成功后,如何返回从自定义用户子类化的 Django 用户?
- google-bigquery - 基于 BigQuery 中其他字段整数的 DateSub 函数
- python - 为什么减去日期时间会产生溢出错误?
- azure - 将 Azure Functions 与事件中心链集成的最佳参数是什么
- python - Python:在迭代标准输出时从子进程中捕获异常
- iis - 在发布托管在 IIS 中的 blazor 程序集应用程序 ASP.NET CORE 后,我收到了 DirectoryNotFoundException 错误
- python - 带有 datetime 和 sharex 的 pandas bar 和 line 子图
- ubuntu - 来自类的计时计时器类传递方法不起作用
- xml - 基于属性引用与 XPath 匹配节点
- c - 如何传递一个 malloc 的指针数组地址,以便我可以更改数组中的指针?