Closed
Description
Hi
What
This is a user feedback about spring data mongodb exception translation:
- In production we encounter a
MongoSocketWriteException
during a simplefindBy...()
- spring-data-mongodb translates this exception into a
org.springframework.data.mongodb.UncategorizedMongoDbException
Here is an extract of the stack:
org.springframework.data.mongodb.UncategorizedMongoDbException: Exception sending message; nested exception is com.mongodb.MongoSocketWriteException: Exception sending message
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:138)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2793)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2698)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:2441)
at org.springframework.data.mongodb.core.ExecutableFindOperationSupport$ExecutableFindSupport.doFind(ExecutableFindOperationSupport.java:214)
at org.springframework.data.mongodb.core.ExecutableFindOperationSupport$ExecutableFindSupport.all(ExecutableFindOperationSupport.java:157)
at org.springframework.data.mongodb.repository.query.MongoQueryExecution$PagedExecution.execute(MongoQueryExecution.java:121)
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:99)
- on our side we would manage
MongoSocketException
and other "resource-related" exceptions in the same way but the translator didn't translateMongoSocketWriteException
case intoDataAccessResourceFailureException
so we can't without checking on our side this kind of mongo exceptions..
Version
We're using spring-data-mongodb 3.0.6.RELEASE
but I saw that the relate code dont change.
List of resource-related exception:
Why
Today I think the translator translates only an exact match between user-exception and RESOURCE_FAILURE_EXCEPTIONS
translation matrix entries.
HowToReproduce
MongoSocketWriteException writeException = new MongoSocketWriteException("oO", null, null);
System.out.println(ClassUtils.getShortName(ClassUtils.getUserClass(writeException.getClass())));
// MongoSocketWriteException
System.out.println(new MongoExceptionTranslator().translateExceptionIfPossible(writeException));
// org.springframework.data.mongodb.UncategorizedMongoDbException: oO; nested exception is com.mongodb.MongoSocketWriteException: oO
Fix Suggest
There is no check on user-exception ancestor.
For example, I expect MongoSocketWriteException
(child of MongoSocketException
) like all other MongoSocketException
childs to be translated into DataAccessResourceFailureException
.
Am I wrong?
If I'm right, do you plan to improve MongoExceptionTranslator
this way ?
Regards