From 4fc52c40a28668b44de5347cc1b2d816f48e3f82 Mon Sep 17 00:00:00 2001 From: Taras Romaniv Date: Thu, 10 Feb 2022 15:20:43 +0200 Subject: [PATCH 1/3] [Bug] Fix issue with incorrect 0 -> '' conversion If invokeResults.Payload === 0, then it was replaced by empty string, which caused buggy behavior. Example case: We have a lambda that returns a number of upvotes for a post. So, when it returned 0, then HTTP response contained '' (empty string) instead. --- src/lambda/routes/invocations/invocationsRoute.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lambda/routes/invocations/invocationsRoute.js b/src/lambda/routes/invocations/invocationsRoute.js index 88523efe6..4f6c460fd 100644 --- a/src/lambda/routes/invocations/invocationsRoute.js +++ b/src/lambda/routes/invocations/invocationsRoute.js @@ -45,9 +45,10 @@ export default function invocationsRoute(lambda, options, v3Utils) { let statusCode = 200 let functionError = null if (invokeResults) { - resultPayload = invokeResults.Payload || '' - statusCode = invokeResults.StatusCode || 200 - functionError = invokeResults.FunctionError || null + let isPayloadDefined = typeof invokeResults.Payload !== 'undefined'; + resultPayload = isPayloadDefined ? invokeResults.Payload : ''; + statusCode = invokeResults.StatusCode || 200; + functionError = invokeResults.FunctionError || null; } const response = h.response(resultPayload).code(statusCode) if (functionError) { From bdf43cc630078a7dc2bdfc33c527ba70a8ba67bd Mon Sep 17 00:00:00 2001 From: Taras Romaniv Date: Tue, 15 Feb 2022 11:55:53 +0100 Subject: [PATCH 2/3] remove semicolons to fix prettier checks --- src/lambda/routes/invocations/invocationsRoute.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lambda/routes/invocations/invocationsRoute.js b/src/lambda/routes/invocations/invocationsRoute.js index 4f6c460fd..06c82de27 100644 --- a/src/lambda/routes/invocations/invocationsRoute.js +++ b/src/lambda/routes/invocations/invocationsRoute.js @@ -45,10 +45,10 @@ export default function invocationsRoute(lambda, options, v3Utils) { let statusCode = 200 let functionError = null if (invokeResults) { - let isPayloadDefined = typeof invokeResults.Payload !== 'undefined'; - resultPayload = isPayloadDefined ? invokeResults.Payload : ''; - statusCode = invokeResults.StatusCode || 200; - functionError = invokeResults.FunctionError || null; + let isPayloadDefined = typeof invokeResults.Payload !== 'undefined' + resultPayload = isPayloadDefined ? invokeResults.Payload : '' + statusCode = invokeResults.StatusCode || 200 + functionError = invokeResults.FunctionError || null } const response = h.response(resultPayload).code(statusCode) if (functionError) { From 911104a63edbda2565275edf06c3c65c8088524d Mon Sep 17 00:00:00 2001 From: Taras Romaniv Date: Tue, 15 Feb 2022 16:30:14 +0100 Subject: [PATCH 3/3] replace 'let' by 'const' to fix esLint warning --- src/lambda/routes/invocations/invocationsRoute.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lambda/routes/invocations/invocationsRoute.js b/src/lambda/routes/invocations/invocationsRoute.js index 06c82de27..904b5c903 100644 --- a/src/lambda/routes/invocations/invocationsRoute.js +++ b/src/lambda/routes/invocations/invocationsRoute.js @@ -45,7 +45,7 @@ export default function invocationsRoute(lambda, options, v3Utils) { let statusCode = 200 let functionError = null if (invokeResults) { - let isPayloadDefined = typeof invokeResults.Payload !== 'undefined' + const isPayloadDefined = typeof invokeResults.Payload !== 'undefined' resultPayload = isPayloadDefined ? invokeResults.Payload : '' statusCode = invokeResults.StatusCode || 200 functionError = invokeResults.FunctionError || null