Skip to content

Commit b33ce44

Browse files
committed
prevent crashing on invalid error reponse
1 parent d67b65e commit b33ce44

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/hyperapp.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,16 @@ where
267267
return Ok(r);
268268
}
269269

270-
let e = serde_json::from_slice::<SendError>(&response_bytes)
271-
.expect("Failed to deserialize response to send()");
272-
return Err(AppSendError::SendError(e));
270+
match serde_json::from_slice::<SendError>(&response_bytes) {
271+
Ok(e) => Err(AppSendError::SendError(e)),
272+
Err(err) => {
273+
error!(
274+
"Failed to deserialize response in send(): {} (payload: {:?})",
275+
err, response_bytes
276+
);
277+
Err(AppSendError::BuildError(BuildError::NoBody))
278+
}
279+
}
273280
}
274281

275282
pub async fn send_rmp<R>(request: Request) -> Result<R, AppSendError>
@@ -292,9 +299,16 @@ where
292299
return Ok(r);
293300
}
294301

295-
let e = rmp_serde::from_slice::<SendError>(&response_bytes)
296-
.expect("Failed to deserialize response to send()");
297-
return Err(AppSendError::SendError(e));
302+
match rmp_serde::from_slice::<SendError>(&response_bytes) {
303+
Ok(e) => Err(AppSendError::SendError(e)),
304+
Err(err) => {
305+
error!(
306+
"Failed to deserialize response in send_rmp(): {} (payload: {:?})",
307+
err, response_bytes
308+
);
309+
Err(AppSendError::BuildError(BuildError::NoBody))
310+
}
311+
}
298312
}
299313

300314
// Enum defining the state persistance behaviour

0 commit comments

Comments
 (0)