Unverified Commit bf92ceeb authored by Roman Zeyde's avatar Roman Zeyde
Browse files

Return errors back to RPC clients

and fix error handling in more places.
parent 2355dbd0
......@@ -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());
}
}
......@@ -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(&params),
"blockchain.transaction.get_merkle" => self.blockchain_transaction_get_merkle(&params),
&_ => 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<Vec<Value>> {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment