public static ProgressEvent handleException()

in aws-ssm-patchbaseline/src/main/java/software/amazon/ssm/patchbaseline/Resource.java [35:91]


    public static ProgressEvent<ResourceModel, CallbackContext> handleException (Exception ex,
                                                                                 ResourceModel model,
                                                                                 String baselineID,
                                                                                 Logger logger) {

        final ProgressEvent<ResourceModel, CallbackContext> progressEvent = new ProgressEvent<>();
        progressEvent.setStatus(OperationStatus.FAILED);
        progressEvent.setErrorCode(HandlerErrorCode.InvalidRequest);

        if (ex instanceof IllegalArgumentException) {
            logger.log(String.format("WARN Handlers were unable to parse CloudFormation request properly. "
                    + "Exception details: %s %n", ex.getMessage()));
        } else if (ex instanceof ResourceInUseException) {
            logger.log(String.format("WARN Patch baseline resource %s was in use while deleting. "
                    + "Exception details: %s %n", baselineID, ex.getMessage()));
        } else if (ex instanceof InvalidResourceIdException) {
            logger.log(String.format("WARN CloudFormation provided invalid patch baseline ID %s. "
                    + "Exception details: %s %n", baselineID, ex.getMessage()));
        } else if (ex instanceof ResourceLimitExceededException) {
            logger.log(String.format("WARN User tried to create patch baseline but exceeded their resource limits. "
                    + "Exception details: %s %n", ex.getMessage()));
        } else if (ex instanceof DoesNotExistException) {
            logger.log(String.format("WARN CloudFormation provided not existed patch baseline ID %s. "
                    + "Exception details: %s %n", baselineID, ex.getMessage()));
            progressEvent.setErrorCode(HandlerErrorCode.NotFound);
        } else if (ex instanceof AlreadyExistsException) {
            logger.log(String.format("WARN User tried to register baseline %s to patch group that already has a baseline. "
                    + "Exception details: %s %n", baselineID, ex.getMessage()));
        } else if (ex instanceof SsmCfnClientSideException) {
            logger.log(String.format("WARN Client-side error in CloudFormation request. "
                    + "Exception details: %s %n", ex.getMessage()));
        } else if (ex instanceof AmazonServiceException) {
            AmazonServiceException ase = (AmazonServiceException)ex;
            logExceptionChain(ase, logger);
            int errorStatus = ase.getStatusCode();
            if (errorStatus >= STATUS_CODE_400 && errorStatus < STATUS_CODE_500) {
                // 400s default to FAILURE
                logger.log(String.format("WARN SSM returned a 4xx error code! Exception details: %s %n", ex.getMessage()));

                if (RETRIABLE_400_ERROR_CODES.contains(ase.getErrorCode())) {
                    // a lot of HTTP timeout exceptions will appear as an
                    // AmazonServiceException with Status Code 400, but we want to retry these, as they aren't actually
                    // client-side errors.
                    logger.log(String.format("INFO Detected HttpTimeoutException. Please RETRY"));
                }
            } else {
                // >= 500s default to RETRY
                logger.log(String.format("ERROR SSM returned a 5xx error code! Please RETRY! Exception details: %s %n", ex.getMessage()));
            }
        } else {
            // response.setMessage(String.format("Internal Failure: %s", ex.getMessage()));
            logger.log(String.format("ERROR Encountered an unknown exception while processing patch baseline request. Exception details: %s %n", ex.getMessage()));
        }

        progressEvent.setMessage(ex.getMessage());
        return progressEvent;
    }