Amazon Lambda / API Gateway / Amazon Lex - Error: Handled
Amazon Lambda / API Gateway / Amazon Lex - Error: Handled
我创建了一个链接到我的 Amazon Lex 机器人的 API 网关。它在过去有效,但由于某种原因,它现在显示此错误消息。当我在 Lex 的 'Test Chatbot' 功能中测试它时,该机器人工作。
我将新函数设置为'Lambda initialization and validation.'
后出现错误
错误信息:
START RequestId: e18b78ef-3177-4e2f-999a-33cd48258a60 Version: $LATEST
2020-01-26T05:37:01.003Z e18b78ef-3177-4e2f-999a-33cd48258a60 ERROR Invoke Error {"errorType":"Error","errorMessage":"handled","stack":["Error: handled"," at _homogeneousError (/var/runtime/CallbackContext.js:13:12)"," at postError (/var/runtime/CallbackContext.js:30:54)"," at done (/var/runtime/CallbackContext.js:57:7)"," at fail (/var/runtime/CallbackContext.js:67:7)"," at /var/runtime/CallbackContext.js:105:16"," at processTicksAndRejections (internal/process/task_queues.js:93:5)"]}END RequestId: e18b78ef-3177-4e2f-999a-33cd48258a60
REPORT RequestId: e18b78ef-3177-4e2f-999a-33cd48258a60 Duration: 579.06 ms Billed Duration: 600 ms Memory Size: 128 MB Max Memory Used: 93 MB
API:
var AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
var lexruntime = new AWS.LexRuntime();
function main(event) {
var params = {
botAlias: 'myBot',
botName: 'myBot',
inputText: event.body.inputText,
userId: 'myUserId'
};
return new Promise((resolve, reject) => {
lexruntime.postText(params, function(err, data) {
if (err) {
var err2 = err.errorMessage
reject(err2)
}
else {
resolve({data})
}
});
});
}
exports.handler = main;
我在错误消息出现之前创建的新函数:
'use strict';
function close(sessionAttributes, intentName, slots, slotToElicit, message) {
return {
sessionAttributes,
dialogAction: {
type: 'ElicitSlot',
intentName: intentName,
slots,
slotToElicit,
message,
},
};
}
function delegate(sessionAttributes, slots){
return {
sessionAttributes: sessionAttributes,
dialogAction: {
type: "Delegate",
slots: slots
}
};
}
function dispatch(intentRequest, callback) {
const sessionAttributes = intentRequest.sessionAttributes;
if(!sessionAttributes.userStatus){
var param1 = {
Email: null
};
intentRequest.currentIntent.slots = param1;
callback(close(sessionAttributes, 'Verify', intentRequest.currentIntent.slots, 'Email', { "contentType": "PlainText", "content": "Please enter your email"}));
}
else {
callback(delegate(sessionAttributes, intentRequest.currentIntent.slots));
}
}
exports.handler = (event, context, callback) => {
try {
dispatch(event,
(response) => {
callback(null, response);
});
} catch (err) {
callback(err);
}
};
错误是什么意思?
我发现了问题:
固定:
function dispatch(intentRequest, callback) {
var sessionAttributes = intentRequest.sessionAttributes;
if(sessionAttributes){
if(sessionAttributes.userStatus){
callback(delegate(sessionAttributes, intentRequest.currentIntent.slots));
}
}
else {
var param1 = {
Email: null
};
intentRequest.currentIntent.slots = param1;
callback(close(sessionAttributes, 'Verify', intentRequest.currentIntent.slots, 'Email'));
}
}
我创建了一个链接到我的 Amazon Lex 机器人的 API 网关。它在过去有效,但由于某种原因,它现在显示此错误消息。当我在 Lex 的 'Test Chatbot' 功能中测试它时,该机器人工作。
我将新函数设置为'Lambda initialization and validation.'
后出现错误错误信息:
START RequestId: e18b78ef-3177-4e2f-999a-33cd48258a60 Version: $LATEST
2020-01-26T05:37:01.003Z e18b78ef-3177-4e2f-999a-33cd48258a60 ERROR Invoke Error {"errorType":"Error","errorMessage":"handled","stack":["Error: handled"," at _homogeneousError (/var/runtime/CallbackContext.js:13:12)"," at postError (/var/runtime/CallbackContext.js:30:54)"," at done (/var/runtime/CallbackContext.js:57:7)"," at fail (/var/runtime/CallbackContext.js:67:7)"," at /var/runtime/CallbackContext.js:105:16"," at processTicksAndRejections (internal/process/task_queues.js:93:5)"]}END RequestId: e18b78ef-3177-4e2f-999a-33cd48258a60
REPORT RequestId: e18b78ef-3177-4e2f-999a-33cd48258a60 Duration: 579.06 ms Billed Duration: 600 ms Memory Size: 128 MB Max Memory Used: 93 MB
API:
var AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
var lexruntime = new AWS.LexRuntime();
function main(event) {
var params = {
botAlias: 'myBot',
botName: 'myBot',
inputText: event.body.inputText,
userId: 'myUserId'
};
return new Promise((resolve, reject) => {
lexruntime.postText(params, function(err, data) {
if (err) {
var err2 = err.errorMessage
reject(err2)
}
else {
resolve({data})
}
});
});
}
exports.handler = main;
我在错误消息出现之前创建的新函数:
'use strict';
function close(sessionAttributes, intentName, slots, slotToElicit, message) {
return {
sessionAttributes,
dialogAction: {
type: 'ElicitSlot',
intentName: intentName,
slots,
slotToElicit,
message,
},
};
}
function delegate(sessionAttributes, slots){
return {
sessionAttributes: sessionAttributes,
dialogAction: {
type: "Delegate",
slots: slots
}
};
}
function dispatch(intentRequest, callback) {
const sessionAttributes = intentRequest.sessionAttributes;
if(!sessionAttributes.userStatus){
var param1 = {
Email: null
};
intentRequest.currentIntent.slots = param1;
callback(close(sessionAttributes, 'Verify', intentRequest.currentIntent.slots, 'Email', { "contentType": "PlainText", "content": "Please enter your email"}));
}
else {
callback(delegate(sessionAttributes, intentRequest.currentIntent.slots));
}
}
exports.handler = (event, context, callback) => {
try {
dispatch(event,
(response) => {
callback(null, response);
});
} catch (err) {
callback(err);
}
};
错误是什么意思?
我发现了问题:
固定:
function dispatch(intentRequest, callback) {
var sessionAttributes = intentRequest.sessionAttributes;
if(sessionAttributes){
if(sessionAttributes.userStatus){
callback(delegate(sessionAttributes, intentRequest.currentIntent.slots));
}
}
else {
var param1 = {
Email: null
};
intentRequest.currentIntent.slots = param1;
callback(close(sessionAttributes, 'Verify', intentRequest.currentIntent.slots, 'Email'));
}
}