comparison json/VampJson.h @ 41:10ac36b7198a

Exception handling in adapter code
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 23 Aug 2016 11:17:01 +0100
parents 183be3bc9d7b
children 62c17e143aba
comparison
equal deleted inserted replaced
40:55d69b26d4db 41:10ac36b7198a
977 jo["errorText"] = ""; 977 jo["errorText"] = "";
978 jo["content"] = fromFeatureSet(resp.features, true); 978 jo["content"] = fromFeatureSet(resp.features, true);
979 return json11::Json(jo); 979 return json11::Json(jo);
980 } 980 }
981 981
982 static json11::Json
983 fromException(const std::exception &e, RRType responseType) {
984
985 json11::Json::object jo;
986
987 if (responseType == RRType::List) jo["type"] = "list";
988 else if (responseType == RRType::Load) jo["type"] = "load";
989 else if (responseType == RRType::Configure) jo["type"] = "configure";
990 else if (responseType == RRType::Process) jo["type"] = "process";
991 else if (responseType == RRType::Finish) jo["type"] = "finish";
992 else jo["type"] = "invalid";
993
994 jo["success"] = false;
995 jo["errorText"] = std::string("exception caught: ") + e.what();
996 return json11::Json(jo);
997 }
998
982 private: // go private briefly for a couple of helper functions 999 private: // go private briefly for a couple of helper functions
983 1000
984 static void 1001 static void
985 checkTypeField(json11::Json j, std::string expected) { 1002 checkTypeField(json11::Json j, std::string expected) {
986 if (!j["type"].is_string()) { 1003 if (!j["type"].is_string()) {