diff options
| author | Wladimir J. van der Laan <[email protected]> | 2012-08-31 17:40:13 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2012-08-31 17:41:58 +0200 |
| commit | b5c1467a7d7d261de5f87d6f26a00cf5ab230dfb (patch) | |
| tree | 5c8b9337c242909db709c80e55ffaf76ee6d0536 | |
| parent | Fix RPC console parser to handle escaped arguments more like bash (diff) | |
| download | discoin-b5c1467a7d7d261de5f87d6f26a00cf5ab230dfb.tar.xz discoin-b5c1467a7d7d261de5f87d6f26a00cf5ab230dfb.zip | |
In RPC console, attempt to format errors
Try to display a nicer message instead of dumping raw JSON object when possible. If the error
somehow doesn't have the required 'code' and 'message' fields, fall back to printing raw JSON object.
| -rw-r--r-- | src/qt/rpcconsole.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 470eba732..6e48fbe8d 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -153,7 +153,8 @@ void RPCExecutor::request(const QString &command) } if(args.empty()) return; // Nothing to do - try { + try + { std::string strPrint; // Convert argument list to JSON objects in method-dependent way, // and pass it along with the method name to the dispatcher. @@ -173,7 +174,17 @@ void RPCExecutor::request(const QString &command) } catch (json_spirit::Object& objError) { - emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(write_string(json_spirit::Value(objError), false))); + try // Nice formatting for standard-format error + { + int code = find_value(objError, "code").get_int(); + std::string message = find_value(objError, "message").get_str(); + emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(message) + " (code " + QString::number(code) + ")"); + } + catch(std::runtime_error &) // raised when converting to invalid type, i.e. missing code or message + { + // Show raw JSON object + emit reply(RPCConsole::CMD_ERROR, QString::fromStdString(write_string(json_spirit::Value(objError), false))); + } } catch (std::exception& e) { |