Description
James Howe opened DATAMONGO-1451 and commented
Currently all WriteConcernException
are translated to DataIntegrityViolationException
, a NonTransientDataAccessException
.
However, a write timeout also throws a WriteConcernException
, for example:
com.mongodb.WriteConcernException: { "serverUsed" : "10.10.17.35:27017" , "ok" : 1 , "n" : 0 , "wtimeout" : true , "err" : "waiting for replication timed out" , "code" : 64}
Logically (IMO) this case should instead be a TransientDataAccessException
, perhaps a subclass of TransientDataAccessResourceException
or QueryTimeoutException
. At least create a MongoWriteTimeoutException
so I can special-case it in exception handlers more easily.
Unfortunately, the WriteConcernException
doesn't appear to provide direct access to the wtimeout
property, so I guess you'd have to use ex.getResponse()
.
My end-goal: I want to return 503 from my controller when it times out, and 500 for other non-transient errors
Affects: 1.8.4 (Gosling SR4), 1.9.1 (Hopper SR1)
Referenced from: pull request #370
1 votes, 2 watchers