【发布时间】:2017-07-07 02:24:35
【问题描述】:
我使用无服务器来实现 Lambda 和 Api 网关。 当我实现错误处理时,下面的代码总是得到 502 bad gateway。
handler.js
module.exports.hello = (event, context, callback) => {
const response = {
statusCode: 400,
headers: {
"Content-Type" : "application/json"
},
body: JSON.stringify({
"status": "error",
"message": "Missing Params"
})
};
callback(response);
};
CloudWatch 记录错误。
{
"errorMessage": "[object Object]"
}
我按照以下 AWS 博客中的“自定义错误对象序列化”方法进行编码。 Ref
【问题讨论】:
标签: amazon-web-services lambda aws-api-gateway serverless-framework