From 73d35f9a2a60f83f856d236af8c8c677cbbc60f9 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Fri, 2 Apr 2021 15:37:40 -0400 Subject: [PATCH] fix: return ES JSON parse error to CFN instead of invoking Lambda retry When an ES request fails due to a bad response, the custom resource should fail. Before this commit, the Lambda function would error and get reinvoked, with CFN eventually giving up on the function reporting "Custom Resource failed to stabilize in expected time". --- src/lib/ElasticSearchClient.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/ElasticSearchClient.js b/src/lib/ElasticSearchClient.js index b7790df..f0eb22e 100644 --- a/src/lib/ElasticSearchClient.js +++ b/src/lib/ElasticSearchClient.js @@ -51,8 +51,8 @@ module.exports = Class.extend({ try { data.body = JSON.parse(responseBody); } catch(e) { - console.log('Invalid JSON body:', responseBody); - throw e; + console.log('Invalid JSON body:', responseBody, e); + deferred.reject(new Error('Request failed due to invalid JSON body. Raw Body: ' + responseBody)); } }