From 6901b7f00e3ac95512cd3c0e398af42d22870f5d Mon Sep 17 00:00:00 2001 From: Charles Chan Date: Fri, 18 Nov 2022 17:48:37 -0800 Subject: [PATCH] Fix #57 - Handle case when subscription was deleted and ExpirationDate is unavailable in Entitlement object --- src/entitlement-sqs.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/entitlement-sqs.js b/src/entitlement-sqs.js index 6858037..fd6e45a 100644 --- a/src/entitlement-sqs.js +++ b/src/entitlement-sqs.js @@ -25,7 +25,8 @@ exports.handler = async (event) => { console.log('entitlementsResponse', entitlementsResponse); - const isExpired = new Date(entitlementsResponse.Entitlements[0].ExpirationDate) < new Date(); + const isExpired = entitlementsResponse.hasOwnProperty("Entitlements") === false || entitlementsResponse.Entitlements.length === 0 || + new Date(entitlementsResponse.Entitlements[0].ExpirationDate) < new Date(); const dynamoDbParams = { TableName: newSubscribersTableName,