driver-core/src/main/com/mongodb/WriteConcernException.java
@Nullable
    public static String extractErrorMessage(final BsonDocument response) {
        if (response.isString("err")) {
            return response.getString("err").getValue();
        } else if (response.isString("errmsg")) {
            return response.getString("errmsg").getValue();
        } else {
            return null;
        }
    }
@Nullable
    public static String extractErrorMessage(final BsonDocument response) {
        if (response.isString("err")) {
            return response.getString("err").getValue();
        } else if (response.isString("errmsg")) {
            return response.getString("errmsg").getValue();
        } else {
            return null;
        }
    }
For internal use only: extract the error message from the response to a write command.

@param response the response
@return the error message