fix(AWS Local Invocation): Fix invalid result handling

This commit is contained in:
Mariusz Nowak 2021-05-21 13:57:42 +02:00 committed by Mariusz Nowak
parent 06c28e2c46
commit bbff0290db

View File

@ -799,7 +799,17 @@ class AwsInvokeLocal {
if (result instanceof Error) {
handleError.call(this, result);
return;
} else if (result.headers && result.headers['Content-Type'] === 'application/json') {
}
try {
JSON.stringify(result);
} catch (error) {
throw new ServerlessError(
`Function returned invalid (not a JSON stringifiable) value: ${inspect(result)}`,
'INVALID_INVOKE_LOCAL_RESULT'
);
}
if (result.headers && result.headers['Content-Type'] === 'application/json') {
if (result.body) {
try {
Object.assign(result, {