private Exception addMessageIfNull()

in common/src/main/java/software/amazon/kms/common/AbstractKmsApiHelper.java [80:92]


    private Exception addMessageIfNull(final String operation, final Exception e) {
        // CloudFormation users only see the message of an exception that resulted in a failure,
        // and do not see its type. Some KMS exceptions (Like MalformedPolicyDocumentException)
        // do not have exception messages, so we need to add one that mentions the exception type and operation.
        final String defaultExceptionMessage = String.format("%s failed due to %s", operation,
                e.getClass().getSimpleName());
        if (!Strings.isNullOrEmpty(e.getMessage()) && e.getMessage().startsWith("null (")) {
            // Replace 'null', while keeping the request id that the SDK adds on
            return new Exception(e.getMessage().replaceFirst("null", defaultExceptionMessage), e);
        }

        return e;
    }