From 1d28731df1da4b7534c679b67deceb2f7e238568 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Sat, 12 Feb 2022 09:20:47 +0100 Subject: [PATCH] impl From for AwcWebSocketError --- libsignal-service-actix/src/websocket.rs | 32 +++++++++++++++++------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/libsignal-service-actix/src/websocket.rs b/libsignal-service-actix/src/websocket.rs index 5de4cbee3..5f62298fd 100644 --- a/libsignal-service-actix/src/websocket.rs +++ b/libsignal-service-actix/src/websocket.rs @@ -22,6 +22,8 @@ pub struct AwcWebSocket { pub enum AwcWebSocketError { #[error("Could not connect to the Signal Server")] ConnectionError(#[from] awc::error::WsClientError), + #[error("Error during Websocket connection")] + ProtocolError(#[from] WsProtocolError), } impl From for ServiceError { @@ -38,19 +40,31 @@ impl From for ServiceError { reason: e.to_string(), }, }, + AwcWebSocketError::ProtocolError(e) => match e { + WsProtocolError::Io(e) => match e.kind() { + std::io::ErrorKind::UnexpectedEof => { + ServiceError::WsClosing { + reason: format!( + "WebSocket closing due to unexpected EOF: {}", + e + ), + } + }, + _ => ServiceError::WsError { + reason: format!( + "IO error during WebSocket connection: {}", + e + ), + }, + }, + e => ServiceError::WsError { + reason: e.to_string(), + }, + }, } } } -impl From for AwcWebSocketError { - fn from(e: WsProtocolError) -> AwcWebSocketError { - todo!("error conversion {:?}", e) - // return Some(Err(ServiceError::WsError { - // reason: e.to_string(), - // })); - } -} - /// Process the WebSocket, until it times out. async fn process( socket_stream: S,