Mercurial > hg > piper-cpp
changeset 180:bd543e74a9bf
Correct the inspection of the JSON object in successful to look for both error and success objects, writing out an error string if neither are present. Revert error handling in readInput() for JSON.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Fri, 03 Feb 2017 11:12:27 +0000 |
parents | 0e13b7b80464 |
children | 376f59073160 |
files | vamp-json/VampJson.h vamp-server/convert.cpp |
diffstat | 2 files changed, 8 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/vamp-json/VampJson.h Fri Feb 03 11:09:37 2017 +0000 +++ b/vamp-json/VampJson.h Fri Feb 03 11:12:27 2017 +0000 @@ -1109,11 +1109,14 @@ static bool successful(json11::Json j, std::string &err) { - if (!j["result"].is_object()) { - err = "result object expected for success"; + if (j["result"].is_object()) { + return true; + } else if (j["error"].is_object()) { + return false; + } else { + err = "result or error object required for valid response"; return false; } - return true; } static void
--- a/vamp-server/convert.cpp Fri Feb 03 11:09:37 2017 +0000 +++ b/vamp-server/convert.cpp Fri Feb 03 11:12:27 2017 +0000 @@ -558,15 +558,8 @@ if (format == "json") { string err; auto result = readInputJson(direction, err, eof); - const bool isRecognisedError = !result.success && result.errorText != ""; - - // if the RequestOrResponse (result) has been populated with success=false and an error message - // then the server returned a well formed error, it is safe to return it for conversion - // -- but if err is populated, something else has gone wrong - if (isRecognisedError || err == "") - return result; - else - throw runtime_error(err); + if (err != "") throw runtime_error(err); + else return result; } else if (format == "capnp") { return readInputCapnp(direction, eof); } else {