我一直从GCP收到一个错误,我正在使用数据存储并在GAE上进行部署。有人有任何想法为什么我会使用javascript promises遇到此错误吗?

我正在使用Google动作在Google主页上打开,如果设备尚未在数据存储区中注册到公寓号码,则要求输入激活密码。如果未注册,它将要求将唯一设备ID与公寓号码相关联的密钥短语。如果唯一标识具有与之关联的公寓,则询问其可以提供什么帮助。

我不确定为什么会说关键路径不完整。我也是新来的诺言!因此,非常感谢您的帮助

UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:99):错误:关键路径元素不能不完整:[激活:]

用这个代码?

datastore.get(datastore.key([ACTIVATION, device_id]))
.then(results => {
    let activation = null
    if (results[0] ) {
        activation = results[0]
    }
    return Promise.resolve(activation)
})
.then(activation => {
    console.log(activation)

    let actionMap = new Map();

    actionMap.set('input.welcome', assistant => {
        console.log('input.welcome')
        if (!activation) {
            assistant.ask("Hello! May I have your key phrase?")
        }
        else {assistant.ask("Welcome back, what can I do for you today?")
        }
    })

    actionMap.set('input.unknown', assistant => {
        console.log('input.unknown')
        if (!activation) {
            assistant.ask("Please provide your activation code")
        } else
        {
            let speech = "OK"
            if (request.body &&
                request.body.result &&
                request.body.result.fulfillment &&
                request.body.result.fulfillment.messages &&
                request.body.result.fulfillment.messages[0] &&
                request.body.result.fulfillment.messages[0].speech) {
                    speech = request.body.result.fulfillment.messages[0].speech
                }
            sendSMSFromUnit(activation.number, request.body.result.resolvedQuery)

            assistant.tell("Got it. ")
        }
})

    actionMap.set('input.keyphrase', assistant => {
        let activationCode = TitleCase([
            assistant.getArgument('Token1'),
            assistant.getArgument('Token2'),
            assistant.getArgument('Token3')
        ].join(" "))
        console.log('activationCode: ' + activationCode)
        if (activation && activation.keyphrase == activationCode) {
            assistant.tell('This device is activated.')
            return
        }

        datastore.get(datastore.key([APARTMENT, activationCode]))
        .then(results => {
            console.log(results)
            if (!results[0]) {
                assistant.ask('Activation unsuccessful.  Can you provide your activation code again?')
                return
            }
            let apartment = results[0]

            datastore.insert({
                key: datastore.key([ACTIVATION, device_id]),
                data: {
                    name: apartment.name,
                    number: apartment.number,
                    keyphrase: activationCode,
                    device_id: device_id
                }
            }).then(() => {
                assistant.ask('Thanks! ')
            })
        })
    })

最佳答案

承诺的整个模式是

Promise((resolve, reject) => {
  // ...
});


现在如何使用它

promiseFunc(...)
   .then((x) => {
     // It get executed well
   })
   .catch((x) => {
     // An error happened
   });




您的代码中缺少.catch部分。因此,如果将错误抛出到您的promise函数中,您将不会捕获它以及节点异常的结果。这就是为什么您有以下警告:Unhandled promise rejection

关于javascript - 未处理的 promise 拒绝-关键路径不完整,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45984467/

10-09 17:58