Mercurial > hg > piper-cpp
comparison vamp-server/convert.cpp @ 184:150cfa0c71e1
Merge pull request #1 from piper-audio/fix/regression-json-responses
Fix/regression json responses
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Fri, 03 Feb 2017 13:00:42 +0000 |
parents | bd543e74a9bf |
children | df381a2e6fa1 |
comparison
equal
deleted
inserted
replaced
172:cfa115746cb3 | 184:150cfa0c71e1 |
---|---|
293 rr.id = readJsonId(j); | 293 rr.id = readJsonId(j); |
294 | 294 |
295 VampJson::BufferSerialisation serialisation = | 295 VampJson::BufferSerialisation serialisation = |
296 VampJson::BufferSerialisation::Array; | 296 VampJson::BufferSerialisation::Array; |
297 | 297 |
298 rr.success = j["success"].bool_value(); | 298 const bool isSuccess = j["result"].is_object(); |
299 rr.errorText = j["errorText"].string_value(); | 299 const bool isError = j["error"].is_object(); |
300 rr.success = isSuccess; | |
301 rr.errorText = isError ? j["error"]["message"].string_value() : ""; | |
300 | 302 |
301 switch (rr.type) { | 303 switch (rr.type) { |
302 | 304 |
303 case RRType::List: | 305 case RRType::List: |
304 rr.listResponse = VampJson::toRpcResponse_List(j, err); | 306 rr.listResponse = VampJson::toRpcResponse_List(j, err); |
333 VampJson::BufferSerialisation::Array); | 335 VampJson::BufferSerialisation::Array); |
334 | 336 |
335 Json id = writeJsonId(rr.id); | 337 Json id = writeJsonId(rr.id); |
336 | 338 |
337 if (!rr.success) { | 339 if (!rr.success) { |
338 | 340 // errorText here likely contains a full message produced by simple-server |
339 j = VampJson::fromError(rr.errorText, rr.type, id); | 341 // setting writeVerbatimError to true avoids doubling error descriptions |
340 | 342 j = VampJson::fromError(rr.errorText, rr.type, id, true); |
341 } else { | 343 |
342 | 344 } else { |
343 switch (rr.type) { | 345 switch (rr.type) { |
344 | 346 |
345 case RRType::List: | 347 case RRType::List: |
346 j = VampJson::fromRpcResponse_List(rr.listResponse, id); | 348 j = VampJson::fromRpcResponse_List(rr.listResponse, id); |
347 break; | 349 break; |
657 if (eof) break; | 659 if (eof) break; |
658 | 660 |
659 writeOutput(outformat, rr); | 661 writeOutput(outformat, rr); |
660 | 662 |
661 } catch (std::exception &e) { | 663 } catch (std::exception &e) { |
662 | |
663 cerr << "Error: " << e.what() << endl; | 664 cerr << "Error: " << e.what() << endl; |
664 exit(1); | 665 exit(1); |
665 } | 666 } |
666 } | 667 } |
667 | 668 |