Better error reporting

This commit is contained in:
Alex Auvolat 2020-04-23 16:23:06 +00:00
parent 82f4cd8719
commit 01a8acdeec
3 changed files with 6 additions and 6 deletions

View file

@ -67,6 +67,7 @@ impl Error {
match self { match self {
Error::BadRequest(_) => StatusCode::BAD_REQUEST, Error::BadRequest(_) => StatusCode::BAD_REQUEST,
Error::NotFound => StatusCode::NOT_FOUND, Error::NotFound => StatusCode::NOT_FOUND,
Error::RPC(_) => StatusCode::SERVICE_UNAVAILABLE,
_ => StatusCode::INTERNAL_SERVER_ERROR, _ => StatusCode::INTERNAL_SERVER_ERROR,
} }
} }

View file

@ -326,7 +326,7 @@ async fn cmd_status(rpc_cli: RpcAddrClient<Message>, rpc_host: SocketAddr) -> Re
cfg.tag, cfg.tag,
cfg.datacenter, cfg.datacenter,
cfg.n_tokens, cfg.n_tokens,
(now_msec() - adv.last_seen)/1000, (now_msec() - adv.last_seen) / 1000,
); );
} }
} }

View file

@ -41,6 +41,8 @@ pub enum RPCError {
RMPEncode(#[error(source)] rmp_serde::encode::Error), RMPEncode(#[error(source)] rmp_serde::encode::Error),
#[error(display = "Messagepack decode error: {}", _0)] #[error(display = "Messagepack decode error: {}", _0)]
RMPDecode(#[error(source)] rmp_serde::decode::Error), RMPDecode(#[error(source)] rmp_serde::decode::Error),
#[error(display = "Too many errors: {:?}", _0)]
TooManyErrors(Vec<String>),
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -222,11 +224,8 @@ impl<M: RpcMessage + 'static> RpcClient<M> {
Ok(results) Ok(results)
} else { } else {
let mut msg = "Too many failures:".to_string(); let errors = errors.iter().map(|e| format!("{}", e)).collect::<Vec<_>>();
for e in errors { Err(Error::from(RPCError::TooManyErrors(errors)))
msg += &format!("\n{}", e);
}
Err(Error::Message(msg))
} }
} }
} }