static HandlerErrorCode translateExceptionToErrorCode()

in aws-iotfleethub-application/src/main/java/software/amazon/iotfleethub/application/Translator.java [41:64]


  static HandlerErrorCode translateExceptionToErrorCode(Exception e, Logger logger) {
    logger.log(String.format("Translating exception \"%s\", stack trace: %s",
            e.getMessage(), ExceptionUtils.getStackTrace(e)));

    // https://docs.aws.amazon.com/iot/latest/apireference/API_Operations_AWS_IoT_Fleet_Hub.html
    if (e instanceof ConflictException) {
      return HandlerErrorCode.ResourceConflict;
    } else if (e instanceof InternalFailureException) {
      return HandlerErrorCode.InternalFailure;
    } else if (e instanceof InvalidRequestException) {
      return HandlerErrorCode.InvalidRequest;
    } else if (e instanceof LimitExceededException) {
      return HandlerErrorCode.ServiceLimitExceeded;
    } else if (e instanceof ResourceNotFoundException) {
      return HandlerErrorCode.NotFound;
    } else if (e instanceof ThrottlingException) {
      return HandlerErrorCode.Throttling;
    } 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;
    }
  }