From c265905f518f8cbea170c5a2774670c60de0e36c Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 24 May 2021 09:34:08 +0200 Subject: [PATCH] refactor(Telemetry): Improve AWS stack error codes (#9510) --- lib/plugins/aws/lib/monitorStack.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/plugins/aws/lib/monitorStack.js b/lib/plugins/aws/lib/monitorStack.js index e1ea3de499c..6d500c993ca 100644 --- a/lib/plugins/aws/lib/monitorStack.js +++ b/lib/plugins/aws/lib/monitorStack.js @@ -105,15 +105,26 @@ module.exports = { stackLatestError.ResourceStatusReason || stackLatestError.ResourceStatus }.`; const errorCode = (() => { - if ( - stackLatestError.ResourceStatusReason && - stackLatestError.ResourceStatusReason.startsWith('Properties validation failed') - ) { - return `AWS_STACK_${action.toUpperCase()}_VALIDATION_ERROR`; + if (stackLatestError.ResourceStatusReason) { + if ( + stackLatestError.ResourceStatusReason.startsWith( + 'Properties validation failed' + ) + ) { + return `AWS_CLOUD_FORMATION_${action.toUpperCase()}_STACK_INTERNAL_VALIDATION_ERROR`; + } + if ( + stackLatestError.ResourceStatusReason.includes('is not authorized to perform') + ) { + return `AWS_CLOUD_FORMATION_${action.toUpperCase()}_STACK_INTERNAL_INSUFFICIENT_PERMISSIONS`; + } } - return `AWS_STACK_${action.toUpperCase()}${resourceTypeToErrorCodePostfix( - stackLatestError.ResourceType - )}_${stackLatestError.ResourceStatus}`; + return ( + `AWS_CLOUD_FORMATION_${action.toUpperCase()}_STACK_INTERNAL` + + `${resourceTypeToErrorCodePostfix(stackLatestError.ResourceType)}_${ + stackLatestError.ResourceStatus + }` + ); })(); throw new ServerlessError(errorMessage, errorCode); }