Skip to content

Commit 135dad6

Browse files
BenHuddlestontrondn
authored andcommitted
MB-30041: Migrate client connection to nlohmann::json
Change-Id: I319d8c1a01c2ab7b7829ba7d419167644dcebb86 Reviewed-on: http://review.couchbase.org/104149 Reviewed-by: Trond Norbye <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 3c80b42 commit 135dad6

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

protocol/connection/client_connection.cc

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "config.h"
1818

1919
#include "client_connection.h"
20-
#include "cJSON_utils.h"
2120
#include "client_mcbp_commands.h"
2221

2322
#include <cbsasl/client.h>
@@ -1405,16 +1404,20 @@ static std::string formatMcbpExceptionMsg(const std::string& prefix,
14051404
// probably a JSON error context that's been included with the response body
14061405
if (mcbp::datatype::is_json(response.getDatatype()) &&
14071406
!response.isSuccess()) {
1408-
unique_cJSON_ptr json =
1409-
unique_cJSON_ptr(cJSON_Parse(response.getDataString().c_str()));
1410-
if (json != nullptr && json->type == cJSON_Object) {
1411-
auto* error = cJSON_GetObjectItem(json.get(), "error");
1412-
if (error != nullptr && error->type == cJSON_Object) {
1413-
auto* ctx = cJSON_GetObjectItem(error, "context");
1414-
if (ctx != nullptr && ctx->type == cJSON_String) {
1415-
context = ctx->valuestring;
1407+
nlohmann::json json;
1408+
try {
1409+
auto json = nlohmann::json::parse(response.getDataString());
1410+
if (json.type() == nlohmann::json::value_t::object) {
1411+
auto error = json.find("error");
1412+
if (error != json.end()) {
1413+
auto ctx = error->find("context");
1414+
if (ctx != error->end() &&
1415+
ctx->type() == nlohmann::json::value_t::string) {
1416+
context = ctx->get<std::string>();
1417+
}
14161418
}
14171419
}
1420+
} catch (const nlohmann::json::exception&) {
14181421
}
14191422
}
14201423
return formatMcbpExceptionMsg(prefix, response.getStatus(), context);

0 commit comments

Comments
 (0)