Limit exception mapper to driver exceptions.
We now only map DriverException's and such that are in the com.datastax.oss package to avoid a catch-all to CassandraUncategorizedException. Closes: #1155
This commit is contained in:
@@ -21,12 +21,6 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.datastax.oss.driver.api.core.AllNodesFailedException;
|
||||
import com.datastax.oss.driver.api.core.DriverException;
|
||||
import com.datastax.oss.driver.api.core.auth.AuthenticationException;
|
||||
import com.datastax.oss.driver.api.core.metadata.Node;
|
||||
import com.datastax.oss.driver.api.core.servererrors.*;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
@@ -36,6 +30,12 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.datastax.oss.driver.api.core.AllNodesFailedException;
|
||||
import com.datastax.oss.driver.api.core.DriverException;
|
||||
import com.datastax.oss.driver.api.core.auth.AuthenticationException;
|
||||
import com.datastax.oss.driver.api.core.metadata.Node;
|
||||
import com.datastax.oss.driver.api.core.servererrors.*;
|
||||
|
||||
/**
|
||||
* Simple {@link PersistenceExceptionTranslator} for Cassandra.
|
||||
* <p>
|
||||
@@ -156,8 +156,13 @@ public class CassandraExceptionTranslator implements CqlExceptionTranslator {
|
||||
return new DataAccessResourceFailureException(message, exception);
|
||||
}
|
||||
|
||||
// unknown or unhandled exception
|
||||
return new CassandraUncategorizedException(message, exception);
|
||||
if (exception instanceof DriverException
|
||||
|| (exception.getClass().getName().startsWith("com.datastax.oss.driver"))) {
|
||||
// unknown or unhandled exception
|
||||
return new CassandraUncategorizedException(message, exception);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.cassandra.core.cql;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -29,7 +28,6 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.data.cassandra.*;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import com.datastax.oss.driver.api.core.DefaultConsistencyLevel;
|
||||
import com.datastax.oss.driver.api.core.NoNodeAvailableException;
|
||||
@@ -232,6 +230,11 @@ class CassandraExceptionTranslatorUnitTests {
|
||||
Arrays.asList(ProtocolVersion.V3, ProtocolVersion.V4)))).isInstanceOf(CassandraUncategorizedException.class);
|
||||
}
|
||||
|
||||
@Test // GH-1155
|
||||
void shouldNotTranslateUnknownExceptions() {
|
||||
assertThat(sut.translateExceptionIfPossible(new UnsupportedOperationException())).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACASS-335
|
||||
void shouldTranslateWithCqlMessage() {
|
||||
|
||||
@@ -241,14 +244,4 @@ class CassandraExceptionTranslatorUnitTests {
|
||||
assertThat(dax).hasRootCauseInstanceOf(InvalidConfigurationInQueryException.class).hasMessage(
|
||||
"Query; CQL [SELECT * FROM person]; err; nested exception is com.datastax.oss.driver.api.core.servererrors.InvalidConfigurationInQueryException: err");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<T> T createInstance(String className, Class<?> argTypes[], Object... args)
|
||||
throws ReflectiveOperationException {
|
||||
|
||||
Class<T> exceptionClass = (Class) ClassUtils.forName(className, getClass().getClassLoader());
|
||||
Constructor<T> constructor = exceptionClass.getDeclaredConstructor(argTypes);
|
||||
|
||||
return constructor.newInstance(args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user