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

fix(ws client): improve error message bad URL #642

Merged
merged 4 commits into from
Jan 6, 2022
Merged
Changes from 3 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
11 changes: 7 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,11 @@ impl TryFrom<Uri> for Target {
Some("ws") => Mode::Plain,
#[cfg(feature = "tls")]
Some("wss") => Mode::Tls,
_ => {
invalid_scheme => {
#[cfg(feature = "tls")]
let err = "URL scheme not supported, expects 'ws' or 'wss'";
let err = format!("{:?} not supported, expects 'ws' or 'wss'", invalid_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)", invalid_scheme);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will print something like Some("http") not supported, expects 'ws' or 'wss'; are we happy with that or would it be better to maybe do something like invalid_scheme.unwrap_or("no scheme")?

Copy link
Member Author

@niklasad1 niklasad1 Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I think your suggestion is better.

return Err(WsHandshakeError::Url(err.into()));
}
};
Expand Down