I'm able to invoke a lambda function from another lambda function using aws-sdk invoke() function. I wrote both lambda functions. The lambda function I invoke, returns context.fail() in case of any error occurrence. I invoke the lambda function like this:
lambda
.invoke({
FunctionName: functionName,
InvocationType: "RequestResponse",
Payload: JSON.stringify({
body: { params },
}),
})
.promise()
.then((res) => console.log(res))
.catch((error) => console.log(error));
when I call the lambda function by API Gateway context.fail() works fine and I get status code 400 as I declared in mapping template. but when I invoke the lambda function directly, I can not catch errors in the above code and it always resolve. How can I catch errors in above code? Thanks