Skip to content

Commit

Permalink
refactor(Telemetry): Improve AWS stack error codes (#9510)
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed May 24, 2021
1 parent bbff029 commit c265905
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/plugins/aws/lib/monitorStack.js
Expand Up @@ -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);
}
Expand Down

0 comments on commit c265905

Please sign in to comment.