TypeError:无法读取属性' state'在调用状态

时间:2018-05-18 09:48:55

标签: node.js amazon-web-services aws-lambda amazon-dynamodb alexa

我尝试使用Alexa在特定日期和时间搜索dynamoDB以查找相应的状态。

我目前在云监视中收到以下错误

TypeError: Cannot read property 'state' of undefined

这是完整的错误



2018-05-18T09:25:50.175Z	73ac1779-5a7d-11e8-85af-e35ca28db9ce	TypeError: Cannot read property 'state' of undefined
at Response.<anonymous> (/var/task/index.js:40:28)
at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:364:18)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:685:12)
&#13;
&#13;
&#13;

我也得到以下

2018-05-18T09:25:50.174Z 73ac1779-5a7d-11e8-85af-e35ca28db9ce已加载数据项: 未定义

任何人都可以帮我解决这个问题吗?

以下是错误引用的行。

&#13;
&#13;
  dbClient.query(params, function (err, data) {
    if (err) {
       // failed to read from table for some reason..
       console.log('failed to load data item:\n' + JSON.stringify(err, null, 2));
       // let skill tell the user that it couldn't find the data 
       sendResponse(context, callback, {
          output: "the data could not be loaded from your database",
          endSession: false
       });
    } else {
       let dataItem = data.Items[0];           
       console.log('loaded data item:\n' + JSON.stringify(dataItem, null, 2));
       // assuming the item has an attribute called "state"..
       sendResponse(context, callback, {
          output: dataItem.state,
          endSession: false
       });
    }
  });
};


function sendResponse(context, callback, responseOptions) {
  if(typeof callback === 'undefined') {
    context.succeed(buildResponse(responseOptions));
  } else {
    callback(null, buildResponse(responseOptions));
  }
}

function buildResponse(options) {
  var alexaResponse = {
    version: "1.0",
    response: {
      outputSpeech: {
        "type": "SSML",
        "ssml": `<speak><prosody rate="slow">${options.output}</prosody></speak>`
      },
      shouldEndSession: options.endSession
    }
  };
  if (options.repromptText) {
    alexaResponse.response.reprompt = {
      outputSpeech: {
        "type": "SSML",
        "ssml": `<speak><prosody rate="slow">${options.reprompt}</prosody></speak>`
      }
    };
  }
  return alexaResponse;
}
&#13;
&#13;
&#13;

更新

我在云观察中也发现了这个错误

&#13;
&#13;
2018-05-18T14:46:37.928Z	3158fac8-ea71-4305-a2be-dda782b58531	Unexpected error occurred in the skill handler! TypeError: Cannot read property 'type' of undefined
at exports.handler (/var/task/index.js:81:17)
&#13;
&#13;
&#13;

并且根据请求,这是加载项

的错误

&#13;
&#13;
2018-05-18T14:46:45.592Z	48df3d5d-5aaa-11e8-aa8c-f3f6ecf5748a	loaded data item:
undefined
&#13;
&#13;
&#13;

0 个答案:

没有答案