summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-12-22 17:58:20 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-01-13 14:40:44 -0500
commitb2820de69b15c120c04406aa1448cbc0aa3fde66 (patch)
tree024381fee10fa6cbbcd35d13a60ed3f924b09e37
parentcf7061c06fb4b8b40550c61aaca9275a16663447 (diff)
downloadmongo-b2820de69b15c120c04406aa1448cbc0aa3fde66.tar.gz
SERVER-21956 DBClientCursor should propagate the correct exception code
-rw-r--r--src/mongo/client/dbclientcursor.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/mongo/client/dbclientcursor.cpp b/src/mongo/client/dbclientcursor.cpp
index 3ecc2a5d7e5..861aa905547 100644
--- a/src/mongo/client/dbclientcursor.cpp
+++ b/src/mongo/client/dbclientcursor.cpp
@@ -361,9 +361,17 @@ BSONObj DBClientCursor::next() {
BSONObj DBClientCursor::nextSafe() {
BSONObj o = next();
- if (this->wasError && strcmp(o.firstElementFieldName(), "$err") == 0) {
- uasserted(13106, str::stream() << "nextSafe(): " << o.toString());
+
+ // Only convert legacy errors ($err) to exceptions. Otherwise, just return the response and the
+ // caller will interpret it as a command error.
+ if (wasError && strcmp(o.firstElementFieldName(), "$err") == 0) {
+ auto code = o["code"].numberInt();
+ if (!code) {
+ code = ErrorCodes::UnknownError;
+ }
+ uasserted(code, o.firstElement().str());
}
+
return o;
}