mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Improved receive error handling
Better errors and messages returned by the push tx API. And better message in the command line receive. Fixes #585
This commit is contained in:
parent
abcecd82c1
commit
3515bf748c
3 changed files with 31 additions and 8 deletions
|
@ -19,6 +19,7 @@ use hyper::client::Response;
|
||||||
use hyper::status::{StatusClass, StatusCode};
|
use hyper::status::{StatusClass, StatusCode};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
use rest::Error;
|
use rest::Error;
|
||||||
|
|
||||||
|
@ -57,15 +58,26 @@ fn check_error(res: hyper::Result<Response>) -> Result<Response, Error> {
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
return Err(Error::Internal(format!("Error during request: {}", e)));
|
return Err(Error::Internal(format!("Error during request: {}", e)));
|
||||||
}
|
}
|
||||||
let response = res.unwrap();
|
let mut response = res.unwrap();
|
||||||
match response.status.class() {
|
match response.status.class() {
|
||||||
StatusClass::Success => Ok(response),
|
StatusClass::Success => Ok(response),
|
||||||
StatusClass::ServerError => Err(Error::Internal(format!("Server error."))),
|
StatusClass::ServerError => {
|
||||||
|
Err(Error::Internal(format!("Server error: {}", err_msg(&mut response))))
|
||||||
|
}
|
||||||
StatusClass::ClientError => if response.status == StatusCode::NotFound {
|
StatusClass::ClientError => if response.status == StatusCode::NotFound {
|
||||||
Err(Error::NotFound)
|
Err(Error::NotFound)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::Argument(format!("Argument error")))
|
Err(Error::Argument(format!("Argument error: {}", err_msg(&mut response))))
|
||||||
},
|
},
|
||||||
_ => Err(Error::Internal(format!("Unrecognized error."))),
|
_ => Err(Error::Internal(format!("Unrecognized error."))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn err_msg(resp: &mut Response) -> String {
|
||||||
|
let mut msg = String::new();
|
||||||
|
if let Err(_) = resp.read_to_string(&mut msg) {
|
||||||
|
"<no message>".to_owned()
|
||||||
|
} else {
|
||||||
|
msg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -440,13 +440,16 @@ where
|
||||||
tx.inputs.len(),
|
tx.inputs.len(),
|
||||||
tx.outputs.len()
|
tx.outputs.len()
|
||||||
);
|
);
|
||||||
self.tx_pool
|
|
||||||
|
let res = self.tx_pool
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.add_to_memory_pool(source, tx)
|
.add_to_memory_pool(source, tx);
|
||||||
.map_err(|e| Error::Internal(format!("Addition to transaction pool failed: {:?}", e)))?;
|
|
||||||
|
|
||||||
Ok(Response::with(status::Ok))
|
match res {
|
||||||
|
Ok(()) => Ok(Response::with(status::Ok)),
|
||||||
|
Err(e) => Err(IronError::from(Error::Argument(format!("{:?}", e))))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -435,7 +435,15 @@ fn wallet_command(wallet_args: &ArgMatches, global_config: GlobalConfig) {
|
||||||
file.read_to_string(&mut contents).expect(
|
file.read_to_string(&mut contents).expect(
|
||||||
"Unable to read transaction file.",
|
"Unable to read transaction file.",
|
||||||
);
|
);
|
||||||
wallet::receive_json_tx_str(&wallet_config, &keychain, contents.as_str()).unwrap();
|
if let Err(e) =
|
||||||
|
wallet::receive_json_tx_str(
|
||||||
|
&wallet_config, &keychain, contents.as_str()) {
|
||||||
|
|
||||||
|
println!("Error receiving transaction, the most likely reasons are:");
|
||||||
|
println!(" * the transaction has already been sent");
|
||||||
|
println!(" * your node isn't running or can't be reached");
|
||||||
|
println!("\nDetailed error: {:?}", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
("send", Some(send_args)) => {
|
("send", Some(send_args)) => {
|
||||||
let amount = send_args.value_of("amount").expect(
|
let amount = send_args.value_of("amount").expect(
|
||||||
|
|
Loading…
Reference in a new issue