diff --git a/src/app.rs b/src/app.rs index 8bbcebd..26ad836 100644 --- a/src/app.rs +++ b/src/app.rs @@ -145,6 +145,6 @@ pub fn main() { let config = Config::from_args(); setup_logging(&config); if let Err(e) = run_server(&config) { - error!("{}", e.display_chain().to_string()); + error!("{}", e.display_chain()); } } diff --git a/src/rpc.rs b/src/rpc.rs index aea76d4..b659913 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -149,7 +149,7 @@ impl Connection { let tx = tx.as_str().chain_err(|| "non-string tx")?; let tx = hex::decode(&tx).chain_err(|| "non-hex tx")?; let tx: Transaction = deserialize(&tx).chain_err(|| "failed to parse tx")?; - let txid = self.query.broadcast(&tx).chain_err(|| "broadcast failed")?; + let txid = self.query.broadcast(&tx)?; Ok(json!(txid.be_hex_string())) } @@ -196,9 +196,15 @@ impl Connection { "blockchain.transaction.get" => self.blockchain_transaction_get(¶ms), "blockchain.transaction.get_merkle" => self.blockchain_transaction_get_merkle(¶ms), &_ => bail!("unknown method {} {:?}", method, params), - }?; + }; // TODO: return application errors should be sent to the client - Ok(json!({"jsonrpc": "2.0", "id": id, "result": result})) + Ok(match result { + Ok(result) => json!({"jsonrpc": "2.0", "id": id, "result": result}), + Err(e) => { + warn!("rpc #{} {} {:?} failed: {}", id, method, params, e.display_chain()); + json!({"jsonrpc": "2.0", "id": id, "error": format!("{}", e)}) + } + }) } fn update_subscriptions(&mut self) -> Result> {