in aws-iot-custommetric/src/main/java/com/amazonaws/iot/custommetric/Translator.java [50:81]
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_CreateCustomMetric.html#API_CreateCustomMetric_Errors
// (+same pages for other APIs)
// For Throttling and InternalFailure, we want CFN to retry, and it will do so based on the error code.
// Reference with Retriable/Terminal in comments for each: https://tinyurl.com/y378qdno
if (e instanceof ResourceAlreadyExistsException) {
return HandlerErrorCode.AlreadyExists;
} else if (e instanceof InvalidRequestException) {
return HandlerErrorCode.InvalidRequest;
} else if (e instanceof LimitExceededException) {
return HandlerErrorCode.ServiceLimitExceeded;
} else if (e instanceof UnauthorizedException) {
return HandlerErrorCode.AccessDenied;
} else if (e instanceof InternalFailureException) {
return HandlerErrorCode.InternalFailure;
} else if (e instanceof ThrottlingException) {
return HandlerErrorCode.Throttling;
} else if (e instanceof ResourceNotFoundException) {
return HandlerErrorCode.NotFound;
} else if (e instanceof IotException && ((IotException) e).statusCode() == 403) {
return HandlerErrorCode.AccessDenied;
} 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;
}
}