【发布时间】:2019-06-21 17:54:59
【问题描述】:
在我的handler.js 上
'use strict';
var lalamove = require('./lalamove/index.js');
module.exports.getEstimate = (event, context, callback) => {
lalamove.getQuotation("hi");
};
我一直在lalamove/index.js上将字符串“hi”传递给getQuotation()
'use strict';
module.exports = {
getQuotation: function(event,context,callback){
const response = {
statusCode: 200,
body: JSON.stringify({ message: event })
}
console.log('response', response);
callback(null,response.body);
}
}
它会记录在控制台日志中。它可以在控制台中使用,但无法返回。当我检查日志时:
ERROR 调用错误 {"errorType":"TypeError","errorMessage":"callback is not afunction","stack":["TypeError: callback is not a function"," at Object.getQuotation (/var/任务/lalamove/index.js:10:9)"," 在 Runtime.module.exports.getEstimate [作为处理程序] (/var/task/handler.js:14:12)"," 在 Runtime.handleOnce (/ var/runtime/Runtime.js:63:25)"," 在 process._tickCallback (internal/process/next_tick.js:68:7)"]}
我尝试删除context,但还是一样,我尝试使用return而不是callback,但它不起作用,我仍然得到:
{"message": "Internal server error"}
而不是
{ statusCode: 200, body: '{"message":"hi"}' }
【问题讨论】:
-
我真的不确定,但我曾经遇到过类似的问题。请尝试在回调中传递 response 而不是 response.body
-
@SiddharthYadav 已经试过了,没用 :(
标签: javascript node.js serverless-framework aws-serverless