Skip to content

Commit

Permalink
fix(ws client): improve error message bad URL (#642)
Browse files Browse the repository at this point in the history
* fix(ws client): improve error message bad URL

* fix nit: uri -> target

* fix nit

* fix grumbles
  • Loading branch information
niklasad1 committed Jan 6, 2022
1 parent 6b88ec2 commit 3749ae2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions client/transport/src/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ impl<'a> WsTransportClientBuilder<'a> {
Ok(uri) => {
// Absolute URI.
if uri.scheme().is_some() {
target = uri.try_into()?;
target = uri.try_into().map_err(|e| {
tracing::error!("Redirection failed: {:?}", e);
e
})?;

// Only build TLS connector if `wss` in redirection URL.
#[cfg(feature = "tls")]
Expand Down Expand Up @@ -434,11 +437,12 @@ impl TryFrom<Uri> for Target {
Some("ws") => Mode::Plain,
#[cfg(feature = "tls")]
Some("wss") => Mode::Tls,
_ => {
invalid_scheme => {
let scheme = invalid_scheme.unwrap_or("no scheme");
#[cfg(feature = "tls")]
let err = "URL scheme not supported, expects 'ws' or 'wss'";
let err = format!("`{}` not supported, expects 'ws' or 'wss'", scheme);
#[cfg(not(feature = "tls"))]
let err = "URL scheme not supported, expects 'ws'";
let err = format!("`{}` not supported, expects 'ws' ('wss' requires the tls feature)", scheme);
return Err(WsHandshakeError::Url(err.into()));
}
};
Expand Down

0 comments on commit 3749ae2

Please sign in to comment.