static BaseHandlerException getCfnException()

in aws-sagemaker-imageversion/src/main/java/software/amazon/sagemaker/imageversion/ExceptionMapper.java [26:63]


    static BaseHandlerException getCfnException(
            final String operation,
            final String resourceType,
            final String resourceName,
            final AwsServiceException e) {

        // The exception thrown due to validation failure does not have error code set,
        // hence we need to check it using error message
        if(StringUtils.isNotBlank(e.getMessage()) && e.getMessage().contains("validation error detected")) {
            throw new CfnInvalidRequestException(operation, e);
        }

        if(e.awsErrorDetails() != null && StringUtils.isNotBlank(e.awsErrorDetails().errorCode())) {
            switch (e.awsErrorDetails().errorCode()) {
                case "UnauthorizedOperation":
                    return new CfnAccessDeniedException(operation, e);
                case "InvalidParameter":
                case "InvalidParameterValue":
                case "ValidationError":
                    return new CfnInvalidRequestException(
                            formatExceptionMessage(operation, resourceType, resourceName), e);
                case "InternalError":
                case "ServiceUnavailable":
                    return new CfnServiceInternalErrorException(operation, e);
                case "ResourceLimitExceeded":
                    return new CfnServiceLimitExceededException(resourceType, "ResourceLimitExceeded", e);
                case "ResourceNotFound":
                    return new CfnNotFoundException(resourceType, resourceName, e);
                case "ResourceInUseException":
                    return new ResourceAlreadyExistsException(resourceType, resourceName, e);
                case "ThrottlingException":
                    return new CfnThrottlingException(operation, e);
                default:
                    return new CfnGeneralServiceException(operation, e);
            }
        }
        throw new CfnGeneralServiceException(operation, e);
    }