Replace expect usage with Result

This commit is contained in:
Tobias Reisinger 2023-12-05 01:42:19 +01:00
parent 9394a1ae52
commit b3228ea6b5
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
11 changed files with 135 additions and 95 deletions
emgauwa-core/src/handlers/v1/ws/controllers

View file

@ -116,14 +116,17 @@ impl StreamHandler<Result<Message, ProtocolError>> for ControllerWs {
let action_res = self.handle_action(&mut pool_conn, ctx, action);
if let Err(e) = action_res {
log::error!("Error handling action: {:?}", e);
ctx.text(serde_json::to_string(&e).expect("Failed to serialize error"));
ctx.text(
serde_json::to_string(&e)
.unwrap_or(format!("Error in handling action: {:?}", e)),
);
}
}
Err(e) => {
log::error!("Error deserializing action: {:?}", e);
ctx.text(
serde_json::to_string(&EmgauwaError::Serialization(e))
.expect("Failed to serialize error"),
.unwrap_or(String::from("Error in deserializing action")),
);
}
},