spring-projects / spring-projects/spring-data-mongodb

Translation of WriteConcernExceptions [DATAMONGO-1451]

Open
#2,362 4 comments 0 reactions 1 assignee View on GitHub

@christophstrobl is already working on this.

Since Dec 30, 2020.

in: repository type: bug
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

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 https://github.com/spring-projects/spring-data-mongodb/pull/370

1 votes, 2 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.