comparison vamp-json/VampJson.h @ 176:60dc013bd69c

Fix handling of parsing json error responses from a server, and allow for re-writing them without changing the error message further.
author Lucas Thompson <dev@lucas.im>
date Tue, 31 Jan 2017 22:56:52 +0000
parents 7532233f8e49
children 1990dd9570d8
comparison
equal deleted inserted replaced
175:7532233f8e49 176:60dc013bd69c
1296 } 1296 }
1297 1297
1298 static json11::Json 1298 static json11::Json
1299 fromError(std::string errorText, 1299 fromError(std::string errorText,
1300 RRType responseType, 1300 RRType responseType,
1301 const json11::Json &id) { 1301 const json11::Json &id,
1302 bool writeVerbatimError = false) {
1302 1303
1303 json11::Json::object jo; 1304 json11::Json::object jo;
1304 markRPC(jo); 1305 markRPC(jo);
1305 1306
1306 std::string type; 1307 std::string type;
1313 else type = "invalid"; 1314 else type = "invalid";
1314 1315
1315 json11::Json::object eo; 1316 json11::Json::object eo;
1316 eo["code"] = 0; 1317 eo["code"] = 0;
1317 1318
1318 if (responseType == RRType::NotValid) { 1319 if (responseType == RRType::NotValid || writeVerbatimError) {
1319 eo["message"] = errorText; 1320 eo["message"] = errorText;
1320 } else { 1321 } else {
1321 eo["message"] = 1322 eo["message"] =
1322 std::string("error in ") + type + " request: " + errorText; 1323 std::string("error in ") + type + " request: " + errorText;
1323 } 1324 }