@@ -218,16 +218,21 @@ namespace {
218218 if (!conversationId.eoo ())
219219 commandBuilder.append (conversationId);
220220
221- if (!client->runCommand (targetDatabase, commandBuilder.obj (), inputObj)) {
222- return Status (ErrorCodes::UnknownError,
223- inputObj[saslCommandErrmsgFieldName].str ());
221+ // Server versions 2.3.2 and earlier may return "ok: 1" with a non-zero "code" field,
222+ // indicating a failure. Subsequent versions should return "ok: 0" on failure with a
223+ // non-zero "code" field to indicate specific failure. In all versions, ok: 1, code: >0
224+ // and ok: 0, code optional, indicate failure.
225+ bool ok = client->runCommand (targetDatabase, commandBuilder.obj (), inputObj);
226+ ErrorCodes::Error code = ErrorCodes::fromInt (
227+ inputObj[saslCommandCodeFieldName].numberInt ());
228+
229+ if (!ok || code != ErrorCodes::OK) {
230+ if (code == ErrorCodes::OK)
231+ code = ErrorCodes::UnknownError;
232+
233+ return Status (code, inputObj[saslCommandErrmsgFieldName].str ());
224234 }
225235
226- int statusCodeInt = inputObj[saslCommandCodeFieldName].Int ();
227- if (0 != statusCodeInt)
228- return Status (ErrorCodes::fromInt (statusCodeInt),
229- inputObj[saslCommandErrmsgFieldName].str ());
230-
231236 isServerDone = inputObj[saslCommandDoneFieldName].trueValue ();
232237 saslCommandPrefix = saslFollowupCommandPrefix;
233238 }
0 commit comments