Skip to content

Commit 52d0974

Browse files
committed
feat(rpc): display possible hyper errors in RPC responses
Signed-off-by: ljedrz <ljedrz@gmail.com>
1 parent cc5fb45 commit 52d0974

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

rpc/src/custom_rpc_server.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ async fn handle_rpc<S: Storage + Send + Sync + 'static>(
102102
let mut body = req.into_body();
103103
let data = match body.data().await {
104104
Some(Ok(data)) => data,
105-
_ => {
106-
let resp = jrt::Response::<(), ()>::error(
107-
jrt::Version::V2,
108-
jrt::Error::with_custom_msg(jrt::ErrorCode::ParseError, "Couldn't read the RPC body"),
109-
None,
110-
);
105+
err_or_none => {
106+
let mut error = jrt::Error::with_custom_msg(jrt::ErrorCode::ParseError, "Couldn't read the RPC body");
107+
if let Some(Err(err)) = err_or_none {
108+
error.data = Some(err.to_string());
109+
}
110+
111+
let resp = jrt::Response::<(), String>::error(jrt::Version::V2, error, None);
111112
let body = serde_json::to_vec(&resp).unwrap_or_default();
112113

113114
return Ok(hyper::Response::new(body.into()));

0 commit comments

Comments
 (0)