Skip to content

Commit 6a4b798

Browse files
authored
Merge pull request #168 from hyperware-ai/j/prevent-crashing
fix: prevent crashing on invalid error reponse
2 parents b7f9f03 + b33ce44 commit 6a4b798

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
@@ -277,9 +277,16 @@ where
277277
return Ok(r);
278278
}
279279

280-
let e = serde_json::from_slice::<SendError>(&response_bytes)
281-
.expect("Failed to deserialize response to send()");
282-
return Err(AppSendError::SendError(e));
280+
match serde_json::from_slice::<SendError>(&response_bytes) {
281+
Ok(e) => Err(AppSendError::SendError(e)),
282+
Err(err) => {
283+
error!(
284+
"Failed to deserialize response in send(): {} (payload: {:?})",
285+
err, response_bytes
286+
);
287+
Err(AppSendError::BuildError(BuildError::NoBody))
288+
}
289+
}
283290
}
284291

285292
pub async fn send_rmp<R>(request: Request) -> Result<R, AppSendError>
@@ -302,9 +309,16 @@ where
302309
return Ok(r);
303310
}
304311

305-
let e = rmp_serde::from_slice::<SendError>(&response_bytes)
306-
.expect("Failed to deserialize response to send()");
307-
return Err(AppSendError::SendError(e));
312+
match rmp_serde::from_slice::<SendError>(&response_bytes) {
313+
Ok(e) => Err(AppSendError::SendError(e)),
314+
Err(err) => {
315+
error!(
316+
"Failed to deserialize response in send_rmp(): {} (payload: {:?})",
317+
err, response_bytes
318+
);
319+
Err(AppSendError::BuildError(BuildError::NoBody))
320+
}
321+
}
308322
}
309323

310324
// Enum defining the state persistance behaviour

0 commit comments

Comments
 (0)