Skip to content

Commit

Permalink
Merge pull request #134 from whisperfish/impl-actix-ws-error
Browse files Browse the repository at this point in the history
impl From<WsProtocolError> for AwcWebSocketError
  • Loading branch information
rubdos authored Feb 14, 2022
2 parents deb01fa + 1d28731 commit 1e065e1
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions libsignal-service-actix/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AwcWebSocketError> for ServiceError {
Expand All @@ -38,19 +40,31 @@ impl From<AwcWebSocketError> 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<WsProtocolError> 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<S: Stream>(
socket_stream: S,
Expand Down

0 comments on commit 1e065e1

Please sign in to comment.