summaryrefslogtreecommitdiff
path: root/src/mongo/rpc/reply_builder_interface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/rpc/reply_builder_interface.cpp')
-rw-r--r--src/mongo/rpc/reply_builder_interface.cpp73
1 files changed, 36 insertions, 37 deletions
diff --git a/src/mongo/rpc/reply_builder_interface.cpp b/src/mongo/rpc/reply_builder_interface.cpp
index 100d63e2261..0bf5170d6ee 100644
--- a/src/mongo/rpc/reply_builder_interface.cpp
+++ b/src/mongo/rpc/reply_builder_interface.cpp
@@ -40,48 +40,47 @@
namespace mongo {
namespace rpc {
- namespace {
- const char kOKField[] = "ok";
- const char kCodeField[] = "code";
- const char kErrorField[] = "errmsg";
-
- // similar to appendCommandStatus (duplicating logic here to avoid cyclic library
- // dependency)
- BSONObj augmentReplyWithStatus(const Status& status, const BSONObj& reply) {
- BSONObjBuilder bob;
- bob.appendElements(reply);
-
- if (!reply.hasField(kOKField)) {
- bob.append(kOKField, status.isOK() ? 1.0 : 0.0);
- }
-
- if (status.isOK()) {
- return bob.obj();
- }
-
- if (!reply.hasField(kErrorField)) {
- bob.append(kErrorField, status.reason());
- }
-
- if (!reply.hasField(kCodeField)) {
- bob.append(kCodeField, status.code());
- }
-
- return bob.obj();
- }
+namespace {
+const char kOKField[] = "ok";
+const char kCodeField[] = "code";
+const char kErrorField[] = "errmsg";
+
+// similar to appendCommandStatus (duplicating logic here to avoid cyclic library
+// dependency)
+BSONObj augmentReplyWithStatus(const Status& status, const BSONObj& reply) {
+ BSONObjBuilder bob;
+ bob.appendElements(reply);
+
+ if (!reply.hasField(kOKField)) {
+ bob.append(kOKField, status.isOK() ? 1.0 : 0.0);
}
- ReplyBuilderInterface&
- ReplyBuilderInterface::setCommandReply(StatusWith<BSONObj> commandReply) {
- auto reply = commandReply.isOK() ? std::move(commandReply.getValue()) : BSONObj();
- return setRawCommandReply(augmentReplyWithStatus(commandReply.getStatus(), reply));
+ if (status.isOK()) {
+ return bob.obj();
}
- ReplyBuilderInterface&
- ReplyBuilderInterface::setCommandReply(Status nonOKStatus, BSONObj extraErrorInfo) {
- invariant(!nonOKStatus.isOK());
- return setRawCommandReply(augmentReplyWithStatus(nonOKStatus, extraErrorInfo));
+ if (!reply.hasField(kErrorField)) {
+ bob.append(kErrorField, status.reason());
}
+ if (!reply.hasField(kCodeField)) {
+ bob.append(kCodeField, status.code());
+ }
+
+ return bob.obj();
+}
+}
+
+ReplyBuilderInterface& ReplyBuilderInterface::setCommandReply(StatusWith<BSONObj> commandReply) {
+ auto reply = commandReply.isOK() ? std::move(commandReply.getValue()) : BSONObj();
+ return setRawCommandReply(augmentReplyWithStatus(commandReply.getStatus(), reply));
+}
+
+ReplyBuilderInterface& ReplyBuilderInterface::setCommandReply(Status nonOKStatus,
+ BSONObj extraErrorInfo) {
+ invariant(!nonOKStatus.isOK());
+ return setRawCommandReply(augmentReplyWithStatus(nonOKStatus, extraErrorInfo));
+}
+
} // namespace rpc
} // namespace mongo