From bbff0290db8a56cf599522c5ec0abc901359a0f9 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Fri, 21 May 2021 13:57:42 +0200 Subject: [PATCH] fix(AWS Local Invocation): Fix invalid result handling --- lib/plugins/aws/invokeLocal/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/plugins/aws/invokeLocal/index.js b/lib/plugins/aws/invokeLocal/index.js index 4d4080c5a..6e73fc60f 100644 --- a/lib/plugins/aws/invokeLocal/index.js +++ b/lib/plugins/aws/invokeLocal/index.js @@ -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, {