Skip to content

Added StatusCodeError when receiving unexpected status code #234

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

Merged
merged 1 commit into from
Jul 13, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,7 @@ impl<'u> ClientBuilder<'u> {
let status = StatusCode::from_u16(response.subject.0);

if status != StatusCode::SwitchingProtocols {
return Err(WebSocketError::ResponseError(
"Status code must be Switching Protocols",
));
return Err(WebSocketError::StatusCodeError(status));
}

let key = self
Expand Down
4 changes: 4 additions & 0 deletions src/result.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! The result type used within Rust-WebSocket
pub use hyper::status::StatusCode;
use hyper::Error as HttpError;
use server::upgrade::HyperIntoWsError;
use std::convert::From;
Expand Down Expand Up @@ -40,6 +41,8 @@ pub enum WebSocketError {
ResponseError(&'static str),
/// Invalid WebSocket data frame error
DataFrameError(&'static str),
/// Received unexpected status code
StatusCodeError(StatusCode),
/// No data available
NoDataAvailable,
/// An input/output error
Expand Down Expand Up @@ -90,6 +93,7 @@ impl Error for WebSocketError {
WebSocketError::TlsHandshakeInterruption => "TLS Handshake interrupted",
WebSocketError::Utf8Error(_) => "UTF-8 failure",
WebSocketError::WebSocketUrlError(_) => "WebSocket URL failure",
WebSocketError::StatusCodeError(_) => "Received unexpected status code",
}
}

Expand Down