This comes out of the discussion on
Improve (ie: more descriptive and unique) error type/code/message response when a shard is unable to serve a query due to a read preference mismatch.
For instance, in the Java driver 2.12.0, in the case of a mismatch (such as primary requested but only secondaries are available), the driver will throw an exception with type MongoServerSelectionException rather than a generic exception. However, in a sharded environment, according to my testing and what Jeff has mentioned in
JAVA-1118 the mongo server (or mongos) doesn't return enough information and the driver is forced to throw a generic exception in this case.
It would be great if the specifics of this error could be passed in the response to the driver so a specific exception can be thrown at this level.