我的node.js启动功能每隔一段时间都会失败 - 没有失败。它在AWS Lambda中托管,用于Alexa技能。当它工作时,Alexa完美地说出了我的查询结果。另一半时间,她说遇到了错误。
这是我与之合作的内容。这只是我对node.js的第二个项目,因此非常感谢示例代码。
var mysql = require('mysql');
var pool = mysql.createConnection({
connectionLimit : 10,
host : 'my host',
user : 'test',
password : 'test',
database: 'test',
});
const handlers = {
'LaunchRequest': function () {
pool.query('SELECT versetext, book, reference FROM myverses ORDER BY RAND() LIMIT 1',
function (error, results, fields) {
// handle if error or no result...
console.log(JSON.stringify(results[0].versetext));
var scripture = JSON.stringify(results[0].versetext).replace(/['"]+/g, '');
var book = JSON.stringify(results[0].book).replace(/['"]+/g, '');
var reference = JSON.stringify(results[0].reference).replace(/['"]+/g, '');
this.emit(':tell', scripture + " " + "<say-as interpret-as='ordinal'>" + book + "</say-as>" + " " + reference);
}.bind(this));
pool.end();
},
'AMAZON.HelpIntent': function () {
const speechOutput = this.t('HELP_MESSAGE');
const reprompt = this.t('HELP_MESSAGE');
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', this.t('STOP_MESSAGE'));
},
'AMAZON.StopIntent': function () {
this.emit(':tell', this.t('STOP_MESSAGE'));
},
'Unhandled': function () {
this.emit(':tell', "Sorry, pal.");
},
};
exports.handler = function (event, context) {
const alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
// To enable string internationalization (i18n) features, set a resources object.
alexa.registerHandlers(handlers);
alexa.execute();
};
这是我每隔一段时间得到的错误日志。这似乎标志着我对results[0]
的使用,但我不确定原因。
{
"errorMessage": "RequestId: 679ead1f-0d5a-11e8-a5b3-fd55e0ced610 Process exited before completing request"
}
Request ID:
"679ead1f-0d5a-11e8-a5b3-fd55e0ced610"
Function Logs:
START RequestId: 679ead1f-0d5a-11e8-a5b3-fd55e0ced610 Version: $LATEST
2018-02-09T05:30:57.207Z 679ead1f-0d5a-11e8-a5b3-fd55e0ced610 TypeError: Cannot read property '0' of undefined
at Object.<anonymous> (/var/task/index.js:35:38)
at Query.Sequence.end (/var/task/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
at /var/task/node_modules/mysql/lib/protocol/Protocol.js:225:14
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
END RequestId: 679ead1f-0d5a-11e8-a5b3-fd55e0ced610
REPORT RequestId: 679ead1f-0d5a-11e8-a5b3-fd55e0ced610 Duration: 83.15 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 45 MB
RequestId: 679ead1f-0d5a-11e8-a5b3-fd55e0ced610 Process exited before completing request
答案 0 :(得分:0)
事实证明问题就像完全删除pool.end();
行一样简单。