Forward handshake errors directly instead of wrapping them in a Other IO error

This allows getting HTTP status codes back to the caller, for example,
and allows proper handling of handshake errors.
pull/32/head
Sebastian Dröge 5 years ago committed by Sebastian Dröge
parent a2b88e46d0
commit 5c594c0549
  1. 15
      src/lib.rs

@ -63,6 +63,7 @@ use tungstenite::{
handshake::{
client::{ClientHandshake, Response},
server::{Callback, NoCallback},
HandshakeError,
},
protocol::{Message, Role, WebSocket, WebSocketConfig},
server,
@ -118,11 +119,12 @@ where
let cli_handshake = ClientHandshake::start(allow_std, request, config)?;
cli_handshake.handshake()
});
f.await.map_err(|e| {
WsError::Io(std::io::Error::new(
f.await.map_err(|e| match e {
HandshakeError::Failure(e) => e,
e => WsError::Io(std::io::Error::new(
std::io::ErrorKind::Other,
e.to_string(),
))
)),
})
}
@ -183,11 +185,12 @@ where
let f = handshake::server_handshake(stream, move |allow_std| {
server::accept_hdr_with_config(allow_std, callback, config)
});
f.await.map_err(|e| {
WsError::Io(std::io::Error::new(
f.await.map_err(|e| match e {
HandshakeError::Failure(e) => e,
e => WsError::Io(std::io::Error::new(
std::io::ErrorKind::Other,
e.to_string(),
))
)),
})
}

Loading…
Cancel
Save