【发布时间】:2018-12-04 11:25:32
【问题描述】:
由于某种原因,当我部署从未见过的云功能时,我的终端上出现了输出。
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint /Users/xxxxx/Desktop/cloud_functions/cloud_functions_live/functions
> eslint .
/Users/xxxxx/Desktop/cloud_functions/cloud_functions_live/functions/index.js
38:5 warning Arrow function expected no return value consistent-return
✖ 1 problem (0 errors, 1 warning)
index.js 中的第 38 行也是返回 return docRef.doc("/payments/${payment}").get()
我在这里输入更多信息只是因为 stackoverflow 说我有太多代码并且不允许我添加更新。我希望这不会违反政策,因为其他人要求提供更多代码,并且另一个人已经对这个问题表示赞同,表明我已经用有限的细节将我的问题表达得足够清楚,以供其他人识别。
exports.stripeCharge = functions.firestore.document('/payments/{payment}').onCreate((snap, context) => {
console.log("payment data", snap);
const payment = snap.data();
console.log("payment data2", payment.token);
//console.log("payment data2", payment.token.idempotency_key);
if (!payment || payment.charge) return;
var docRef = admin.firestore()
const idempotency_key = payment.idempotency_key; // prevent duplicate charges
//.document(`/payments/${payment}`);
//var docRef =
return docRef.doc(`/payments/${payment}`).get()
.then(snapshot => {
console.log("augu", snapshot);
return snapshot;
})
.then(customer => {
const amount = payment.amount;
const source = payment.token;
const currency = payment.currency;
const charge = {amount, currency, source};
console.log("brett", charge);
return stripe.charges.create(charge, { idempotency_key });
})
.then(charge => {
console.log("set charge back");
return docRef.doc(`/charges/${idempotency_key}`).set(charge);
})
})
【问题讨论】:
-
第 38 行是哪一行?你能展示整个函数吗?
-
顶一个我的错,我会做一个快速编辑
-
你能展示整个函数吗?
-
当然,Stackoverflow 只是抱怨输入的代码太多
-
通常希望您提供重现问题的最少代码。如果您可以将您的功能提炼到最低限度以找出问题所在,那就更容易了。
标签: javascript node.js firebase google-cloud-functions eslint