【发布时间】:2017-06-23 08:16:37
【问题描述】:
我创建了一个具有以下代码的简单 lambda 函数。
exports.handler = (event, context, callback) => {
const operation = event.body.operation;
console.log("operation = ", operation)
switch (operation) {
case 'add': callback(null, 'post method');
break;
case 'add1': callback(null, {
status: 0,
errorType: "InternalServerError",
errorCode: "001",
errorMessage: "post method error."
}
);
default: callback(null, 'Hello from Lambda');
break;
}
};
它将与 Amazon API Gateway 连接。使用能够获得成功和错误响应的 REST 客户端。但是 HTTP 状态码仍然是 200。然后我通过两种方式修改了 API Gateway 集成响应。
1. Selection pattern : “InternalServerError”
2. Selection pattern : “.*InternalServerError”
Method response : 500
但我仍然得到 200 HTTP 状态码。与此选择模式相关的实际问题是什么?
【问题讨论】:
-
您是否需要使用
context.fail()? (向下滚动过去接受的答案并阅读其他答案。)
标签: node.js rest amazon-web-services aws-lambda aws-api-gateway