|
17 | 17 | #include "config.h" |
18 | 18 |
|
19 | 19 | #include "client_connection.h" |
20 | | -#include "cJSON_utils.h" |
21 | 20 | #include "client_mcbp_commands.h" |
22 | 21 |
|
23 | 22 | #include <cbsasl/client.h> |
@@ -1405,16 +1404,20 @@ static std::string formatMcbpExceptionMsg(const std::string& prefix, |
1405 | 1404 | // probably a JSON error context that's been included with the response body |
1406 | 1405 | if (mcbp::datatype::is_json(response.getDatatype()) && |
1407 | 1406 | !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 | + } |
1416 | 1418 | } |
1417 | 1419 | } |
| 1420 | + } catch (const nlohmann::json::exception&) { |
1418 | 1421 | } |
1419 | 1422 | } |
1420 | 1423 | return formatMcbpExceptionMsg(prefix, response.getStatus(), context); |
|
0 commit comments