Skip to content

Commit 84c0ec1

Browse files
bjorihanumantmk
authored andcommitted
CDRIVER-546: Use the error message from the server rather then cryptic home grown one
Closes #180
1 parent 0cd6c4b commit 84c0ec1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/mongoc/mongoc-cluster.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,13 +1794,21 @@ _mongoc_cluster_auth_node_scram (mongoc_cluster_t *cluster,
17941794
!(conv_id = bson_iter_int32 (&iter)) ||
17951795
!bson_iter_init_find (&iter, &reply, "payload") ||
17961796
!BSON_ITER_HOLDS_BINARY(&iter)) {
1797+
const char *errmsg = "Received invalid SCRAM reply from MongoDB server.";
1798+
17971799
MONGOC_INFO ("SCRAM: authentication failed for \"%s\"",
17981800
mongoc_uri_get_username (cluster->uri));
1799-
bson_destroy (&reply);
1801+
1802+
if (bson_iter_init_find (&iter, &reply, "errmsg") &&
1803+
BSON_ITER_HOLDS_UTF8 (&iter)) {
1804+
errmsg = bson_iter_utf8 (&iter, NULL);
1805+
}
1806+
18001807
bson_set_error (error,
18011808
MONGOC_ERROR_CLIENT,
18021809
MONGOC_ERROR_CLIENT_AUTHENTICATE,
1803-
"Received invalid SCRAM reply from MongoDB server.");
1810+
"%s", errmsg);
1811+
bson_destroy (&reply);
18041812
goto failure;
18051813
}
18061814

0 commit comments

Comments
 (0)