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, {