diff --git a/src/main/java/software/amazon/cloudformation/exceptions/BaseHandlerException.java b/src/main/java/software/amazon/cloudformation/exceptions/BaseHandlerException.java index 82ae4996..167e91fe 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/BaseHandlerException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/BaseHandlerException.java @@ -22,7 +22,7 @@ public abstract class BaseHandlerException extends RuntimeException { private static final long serialVersionUID = -1646136434112354328L; - private HandlerErrorCode errorCode; + private final HandlerErrorCode errorCode; protected BaseHandlerException(final Throwable cause, final HandlerErrorCode errorCode) { @@ -33,7 +33,7 @@ protected BaseHandlerException(final Throwable cause, protected BaseHandlerException(final String message, final Throwable cause, final HandlerErrorCode errorCode) { - super(message, cause); + super(String.format("%s %s", message, cause.getMessage()), cause); this.errorCode = errorCode; } diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnAccessDeniedException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnAccessDeniedException.java index 1ad6a516..606d5eb6 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnAccessDeniedException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnAccessDeniedException.java @@ -26,7 +26,7 @@ public CfnAccessDeniedException(final Throwable cause) { } public CfnAccessDeniedException(final String operation) { - this(operation, null); + super(String.format(ERROR_CODE.getMessage(), operation), ERROR_CODE); } public CfnAccessDeniedException(final String operation, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnAlreadyExistsException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnAlreadyExistsException.java index 4c55fa67..881ae195 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnAlreadyExistsException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnAlreadyExistsException.java @@ -27,7 +27,7 @@ public CfnAlreadyExistsException(final Throwable cause) { public CfnAlreadyExistsException(final String resourceTypeName, final String resourceIdentifier) { - this(resourceTypeName, resourceIdentifier, null); + super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier), ERROR_CODE); } public CfnAlreadyExistsException(final String resourceTypeName, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnGeneralServiceException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnGeneralServiceException.java index b1429dd0..ec6c3ac7 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnGeneralServiceException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnGeneralServiceException.java @@ -26,7 +26,7 @@ public CfnGeneralServiceException(final Throwable cause) { } public CfnGeneralServiceException(final String operation) { - this(operation, null); + super(String.format(ERROR_CODE.getMessage(), operation), ERROR_CODE); } public CfnGeneralServiceException(final String operation, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnInternalFailureException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnInternalFailureException.java index 782f3606..acd881b8 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnInternalFailureException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnInternalFailureException.java @@ -22,7 +22,7 @@ public class CfnInternalFailureException extends BaseHandlerException { private static final HandlerErrorCode ERROR_CODE = HandlerErrorCode.InternalFailure; public CfnInternalFailureException() { - this(null); + super(ERROR_CODE.getMessage(), ERROR_CODE); } public CfnInternalFailureException(final Throwable cause) { diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnInvalidRequestException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnInvalidRequestException.java index 5b581bb7..9aa7dd15 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnInvalidRequestException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnInvalidRequestException.java @@ -26,7 +26,7 @@ public CfnInvalidRequestException(final Throwable cause) { } public CfnInvalidRequestException(final String requestBody) { - this(requestBody, null); + super(String.format(ERROR_CODE.getMessage(), requestBody), ERROR_CODE); } public CfnInvalidRequestException(final String requestBody, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnNetworkFailureException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnNetworkFailureException.java index 8055210b..90865a7f 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnNetworkFailureException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnNetworkFailureException.java @@ -26,7 +26,7 @@ public CfnNetworkFailureException(final Throwable cause) { } public CfnNetworkFailureException(final String operation) { - this(operation, null); + super(String.format(ERROR_CODE.getMessage(), operation), ERROR_CODE); } public CfnNetworkFailureException(final String operation, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotFoundException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotFoundException.java index 7c27f186..1557be2a 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotFoundException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotFoundException.java @@ -27,7 +27,7 @@ public CfnNotFoundException(final Throwable cause) { public CfnNotFoundException(final String resourceTypeName, final String resourceIdentifier) { - this(resourceTypeName, resourceIdentifier, null); + super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier), ERROR_CODE); } public CfnNotFoundException(final String resourceTypeName, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java index 071e2681..fcb2e59b 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java @@ -27,7 +27,7 @@ public CfnNotStabilizedException(final Throwable cause) { public CfnNotStabilizedException(final String resourceTypeName, final String resourceIdentifier) { - this(resourceTypeName, resourceIdentifier, null); + super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier), ERROR_CODE); } public CfnNotStabilizedException(final String resourceTypeName, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotUpdatableException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotUpdatableException.java index fddf4e9d..56ea700c 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotUpdatableException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotUpdatableException.java @@ -27,7 +27,7 @@ public CfnNotUpdatableException(final Throwable cause) { public CfnNotUpdatableException(final String resourceTypeName, final String resourceIdentifier) { - this(resourceTypeName, resourceIdentifier, null); + super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier), ERROR_CODE); } public CfnNotUpdatableException(final String resourceTypeName, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnResourceConflictException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnResourceConflictException.java index aa113560..659d69a7 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnResourceConflictException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnResourceConflictException.java @@ -28,7 +28,7 @@ public CfnResourceConflictException(final Throwable cause) { public CfnResourceConflictException(final String resourceTypeName, final String resourceIdentifier, final String conflictReason) { - this(resourceTypeName, resourceIdentifier, conflictReason, null); + super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier, conflictReason), ERROR_CODE); } public CfnResourceConflictException(final String resourceTypeName, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnServiceInternalErrorException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnServiceInternalErrorException.java index 2d7f37df..e3959837 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnServiceInternalErrorException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnServiceInternalErrorException.java @@ -26,7 +26,7 @@ public CfnServiceInternalErrorException(final Throwable cause) { } public CfnServiceInternalErrorException(final String operation) { - this(operation, null); + super(String.format(ERROR_CODE.getMessage(), operation), ERROR_CODE); } public CfnServiceInternalErrorException(final String operation, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnServiceLimitExceededException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnServiceLimitExceededException.java index f1d3e24c..de73a12a 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnServiceLimitExceededException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnServiceLimitExceededException.java @@ -27,7 +27,7 @@ public CfnServiceLimitExceededException(final Throwable cause) { public CfnServiceLimitExceededException(final String resourceTypeName, final String reason) { - this(resourceTypeName, reason, null); + super(String.format(ERROR_CODE.getMessage(), resourceTypeName, reason), ERROR_CODE); } public CfnServiceLimitExceededException(final String resourceTypeName, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnThrottlingException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnThrottlingException.java index 7a085e28..d7fa5495 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnThrottlingException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnThrottlingException.java @@ -26,7 +26,7 @@ public CfnThrottlingException(final Throwable cause) { } public CfnThrottlingException(final String operation) { - this(operation, null); + super(String.format(ERROR_CODE.getMessage(), operation), ERROR_CODE); } public CfnThrottlingException(final String operation, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/ResourceAlreadyExistsException.java b/src/main/java/software/amazon/cloudformation/exceptions/ResourceAlreadyExistsException.java index 29fec57f..fc7f21ab 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/ResourceAlreadyExistsException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/ResourceAlreadyExistsException.java @@ -30,7 +30,7 @@ public ResourceAlreadyExistsException(final Throwable cause) { public ResourceAlreadyExistsException(final String resourceTypeName, final String resourceIdentifier) { - this(resourceTypeName, resourceIdentifier, null); + super(resourceTypeName, resourceIdentifier); } public ResourceAlreadyExistsException(final String resourceTypeName, diff --git a/src/main/java/software/amazon/cloudformation/exceptions/ResourceNotFoundException.java b/src/main/java/software/amazon/cloudformation/exceptions/ResourceNotFoundException.java index 182085ac..723b7349 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/ResourceNotFoundException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/ResourceNotFoundException.java @@ -30,7 +30,7 @@ public ResourceNotFoundException(final Throwable cause) { public ResourceNotFoundException(final String resourceTypeName, final String resourceIdentifier) { - this(resourceTypeName, resourceIdentifier, null); + super(resourceTypeName, resourceIdentifier); } public ResourceNotFoundException(final String resourceTypeName, diff --git a/src/test/java/software/amazon/cloudformation/exceptions/CfnGeneralServiceExceptionTests.java b/src/test/java/software/amazon/cloudformation/exceptions/CfnGeneralServiceExceptionTests.java index 04e765c6..244e9e15 100644 --- a/src/test/java/software/amazon/cloudformation/exceptions/CfnGeneralServiceExceptionTests.java +++ b/src/test/java/software/amazon/cloudformation/exceptions/CfnGeneralServiceExceptionTests.java @@ -56,4 +56,11 @@ public void cfnGeneralServiceException_errorMessage() { throw new CfnGeneralServiceException(new RuntimeException("something wrong")); }).satisfies(exception -> assertEquals("something wrong", exception.getMessage())); } + + @Test + public void cfnGeneralServiceException_detailedErrorMessage() { + assertThatExceptionOfType(CfnGeneralServiceException.class).isThrownBy(() -> { + throw new CfnGeneralServiceException("Some operation", new RuntimeException("something wrong")); + }).satisfies(exception -> assertEquals("Error occurred during operation 'Some operation'. something wrong", exception.getMessage())); + } }