static HandlerErrorCode translateExceptionToErrorCode()

in aws-iot-resourcespecificlogging/src/main/java/software/amazon/iot/resourcespecificlogging/ExceptionTranslator.java [37:68]


    static HandlerErrorCode translateExceptionToErrorCode(Exception e, Logger logger) {

        logger.log(String.format("Translating exception \"%s\", stack trace: %s",
                e.getMessage(), ExceptionUtils.getStackTrace(e)));

        /**
         *  We're handling all the exceptions documented in API docs
         *  https://docs.aws.amazon.com/iot/latest/apireference/API_SetV2LoggingLevel.html (+similar pages for other APIs)
         *  For Throttling and InternalFailure, we want CFN to retry, and it will do so based on the exception type.
         *  Reference with Retriable/Terminal in comments for each: https://tinyurl.com/y378qdno
         */
        if (e instanceof InvalidRequestException) {
            return HandlerErrorCode.InvalidRequest;
        } else if (e instanceof UnauthorizedException || (e instanceof IotException && ((IotException) e).statusCode() == 403)) {
            return HandlerErrorCode.AccessDenied;
        } else if (e instanceof InternalFailureException) {
            return HandlerErrorCode.InternalFailure;
        } else if (e instanceof ThrottlingException) {
            return HandlerErrorCode.Throttling;
        } else if (e instanceof LimitExceededException) {
            return HandlerErrorCode.ServiceLimitExceeded;
        } else if (e instanceof ServiceUnavailableException) {
            return HandlerErrorCode.GeneralServiceException;
        } else if (e instanceof NotConfiguredException) {
            return HandlerErrorCode.NotFound;
        } else {
            logger.log(String.format("Unexpected exception \"%s\", stack trace: %s",
                    e.getMessage(), ExceptionUtils.getStackTrace(e)));
            // Any other exception at this point is unexpected.
            return HandlerErrorCode.InternalFailure;
        }
    }