【发布时间】:2020-04-22 03:00:53
【问题描述】:
我使用this tutorial 作为了解 Dialogflow 和 Firebase 的主要方式,但我陷入了以下代码部分:
25 if(action === 'firebase.update'){
26 let userId = 'marc.tuinier';
27 // Check if the user is in our DB
28 admin.firestore().collection('users').where('userId', '==', userId).limit(1).get()
29 .then(snapshot => {
30 let user = snapshot.docs[0]
31 if (!user) {
32 // Add the user to DB
33 admin.firestore().collection('users').add({
34 userId: userId
35 }).then(ref => {
36 sendResponse('Added new user');
37 });
38 } else {
39 // User in DB
40 sendResponse('User already exists');
41 }
42 });
43 }
我收到以下错误:
28:9 error Expected catch() or return promise/catch-or-return
31:17 error Each then() should return a value or throw promise/always-return
33:21 error Expected catch() or return promise/catch-or-return
33:21 warning Avoid nesting promises promise/no-nesting
35:29 error Each then() should return a value or throw promise/always-return
我主要想知道如何修复这些错误(也许还有一些材料,以便我可以了解更多信息 - 在此先感谢!)
【问题讨论】:
-
我建议对这些 lint 消息中的每一条进行搜索,以了解您的代码可能存在的错误类型。这里有三种不同类型的错误。
标签: javascript firebase firebase-realtime-database google-cloud-functions dialogflow-es-fulfillment