Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl From<WsProtocolError> for AwcWebSocketError #134

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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