[JAVA-2469] Distinguish between error conditions when server selection fails Created: 13/Mar/17 Updated: 14/Mar/17 Resolved: 14/Mar/17 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Cluster Management |
| Affects Version/s: | 3.2.1 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Joshua Matsuoka | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Hi, We have an application that uses Mongodb as a backend for storage. We create a MongoClient, get the required MongoDatabase, then test the connection by performing a count command. The problem we're having is if there is no server listening at the specified address, or authentication fails, BaseCluster.selectServer will throw a MongoTimeoutException. We want to distinguish between various error conditions so that the user can be given a meaningful hint as to what can be done, but it seems like the only way to do this would be to do some String matching on the exception message, which we'd like to avoid. Would it be acceptable to pass the actual ClusterDescription object back with the exception, perhaps as part of a new type of exception (e.g. MongoClusterTimeoutException) so that we have access to the ServerDescriptions and the original exception that ocurred (e.g. MongoSecurityException in the case of failed authentication)? If not, is there a better way to distinguish between error conditions without needing to do matching on the exception message? |
| Comments |
| Comment by Jeffrey Yemin [ 14/Mar/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Glad to hear it. Good luck! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Joshua Matsuoka [ 14/Mar/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Jeff, This should work. Thanks! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 13/Mar/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Another possibility is to register a ClusterListener:
|