Mercurial > hg > piper-cpp
diff vamp-server/convert.cpp @ 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 | 59c89b0e9375 |
children | bd543e74a9bf |
line wrap: on
line diff
--- a/vamp-server/convert.cpp Tue Jan 31 22:54:08 2017 +0000 +++ b/vamp-server/convert.cpp Tue Jan 31 22:56:52 2017 +0000 @@ -337,11 +337,11 @@ Json id = writeJsonId(rr.id); if (!rr.success) { - - j = VampJson::fromError(rr.errorText, rr.type, id); + // errorText here likely contains a full message produced by simple-server + // setting writeVerbatimError to true avoids doubling error descriptions + j = VampJson::fromError(rr.errorText, rr.type, id, true); } else { - switch (rr.type) { case RRType::List: @@ -558,8 +558,15 @@ if (format == "json") { string err; auto result = readInputJson(direction, err, eof); - if (err != "") throw runtime_error(err); - else return result; + 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); } else if (format == "capnp") { return readInputCapnp(direction, eof); } else { @@ -661,7 +668,6 @@ writeOutput(outformat, rr); } catch (std::exception &e) { - cerr << "Error: " << e.what() << endl; exit(1); }