dnetview: propagate errors more descriptively

This commit is contained in:
lunar-mining
2022-05-19 12:09:47 +02:00
parent fe69bf144a
commit 4541e00eac
2 changed files with 7 additions and 7 deletions

View File

@@ -43,10 +43,8 @@ struct DnetView {
impl DnetView {
async fn new(url: Url, name: String) -> Result<Self> {
match RpcClient::new(url).await {
Ok(rpc_client) => return Ok(Self { name, rpc_client }),
Err(e) => return Err(Error::OperationFailed),
}
let rpc_client = RpcClient::new(url).await?;
Ok(Self { name, rpc_client })
}
// --> {"jsonrpc": "2.0", "method": "ping", "params": [], "id": 42}
@@ -58,11 +56,11 @@ impl DnetView {
//--> {"jsonrpc": "2.0", "method": "poll", "params": [], "id": 42}
// <-- {"jsonrpc": "2.0", "result": {"nodeID": [], "nodeinfo" [], "id": 42}
async fn get_info(&self) -> Result<Value> {
async fn get_info(&self) -> DnetViewResult<Value> {
let req = jsonrpc::request(json!("get_info"), json!([]));
match self.rpc_client.request(req).await {
Ok(req) => return Ok(req),
Err(_e) => return Err(Error::OperationFailed),
Err(e) => return Err(DnetViewError::Darkfi(e)),
}
}
}

View File

@@ -17,7 +17,7 @@ use crate::{
error::{DnetViewError, DnetViewResult},
model::{NodeInfo, SelectableObject},
};
//use log::debug;
use log::debug;
#[derive(Debug)]
pub struct View {
@@ -99,6 +99,8 @@ impl View {
// remove any duplicates
id_list.dedup();
//debug!("ID LIST {:?}", id_list);
//debug!("ACTIVE ID LIST {:?}", self.active_ids.ids);
if id_list.is_empty() {
// we have not received any data
Ok(())