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 4 years ago committed by Sebastian Dröge
parent a2b88e46d0
commit 5c594c0549
  1. 15
      src/lib.rs

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

Loading…
Cancel
Save