io.deepsense.neptune.clientlibrary.utils.exceptions.ApiExceptionWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neptune-client-library Show documentation
Show all versions of neptune-client-library Show documentation
Enables integration with Neptune in your Java code
/**
* Copyright (c) 2016, CodiLime Inc.
*/
package io.deepsense.neptune.clientlibrary.utils.exceptions;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.deepsense.neptune.apiclient.ApiException;
import io.deepsense.neptune.clientlibrary.exceptions.common.NeptuneRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public final class ApiExceptionWrapper {
private static final Logger logger = LoggerFactory.getLogger(ApiExceptionWrapper.class);
private ApiExceptionWrapper() {
}
public static NeptuneRuntimeException wrappedApiException(ApiException apiException) {
try {
ObjectMapper objectMapper = new ObjectMapper();
ApiExceptionBody apiExceptionBody =
objectMapper.readValue(apiException.getResponseBody(), ApiExceptionBody.class);
return new NeptuneRuntimeException(apiExceptionBody.getMessage(), apiException);
} catch (IOException ioException) {
logger.error(
"Failed to parse the body of an ApiException: %s, cause: %s",
apiException,
ioException);
return new NeptuneRuntimeException("Operation failed!", apiException);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy