Skip to content

Commit c265905

Browse files
authored
refactor(Telemetry): Improve AWS stack error codes (serverless#9510)
1 parent bbff029 commit c265905

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

lib/plugins/aws/lib/monitorStack.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,26 @@ module.exports = {
105105
stackLatestError.ResourceStatusReason || stackLatestError.ResourceStatus
106106
}.`;
107107
const errorCode = (() => {
108-
if (
109-
stackLatestError.ResourceStatusReason &&
110-
stackLatestError.ResourceStatusReason.startsWith('Properties validation failed')
111-
) {
112-
return `AWS_STACK_${action.toUpperCase()}_VALIDATION_ERROR`;
108+
if (stackLatestError.ResourceStatusReason) {
109+
if (
110+
stackLatestError.ResourceStatusReason.startsWith(
111+
'Properties validation failed'
112+
)
113+
) {
114+
return `AWS_CLOUD_FORMATION_${action.toUpperCase()}_STACK_INTERNAL_VALIDATION_ERROR`;
115+
}
116+
if (
117+
stackLatestError.ResourceStatusReason.includes('is not authorized to perform')
118+
) {
119+
return `AWS_CLOUD_FORMATION_${action.toUpperCase()}_STACK_INTERNAL_INSUFFICIENT_PERMISSIONS`;
120+
}
113121
}
114-
return `AWS_STACK_${action.toUpperCase()}${resourceTypeToErrorCodePostfix(
115-
stackLatestError.ResourceType
116-
)}_${stackLatestError.ResourceStatus}`;
122+
return (
123+
`AWS_CLOUD_FORMATION_${action.toUpperCase()}_STACK_INTERNAL` +
124+
`${resourceTypeToErrorCodePostfix(stackLatestError.ResourceType)}_${
125+
stackLatestError.ResourceStatus
126+
}`
127+
);
117128
})();
118129
throw new ServerlessError(errorMessage, errorCode);
119130
}

0 commit comments

Comments
 (0)