Skip to content

Commit f1ad464

Browse files
committed
Added StatusCodeError when receiving unexpected status code
1 parent b0a3c5a commit f1ad464

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/client/builder.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,9 +844,7 @@ impl<'u> ClientBuilder<'u> {
844844
let status = StatusCode::from_u16(response.subject.0);
845845

846846
if status != StatusCode::SwitchingProtocols {
847-
return Err(WebSocketError::ResponseError(
848-
"Status code must be Switching Protocols",
849-
));
847+
return Err(WebSocketError::StatusCodeError(status));
850848
}
851849

852850
let key = self

src/result.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! The result type used within Rust-WebSocket
22
3+
pub use hyper::status::StatusCode;
34
use hyper::Error as HttpError;
45
use server::upgrade::HyperIntoWsError;
56
use std::convert::From;
@@ -40,6 +41,8 @@ pub enum WebSocketError {
4041
ResponseError(&'static str),
4142
/// Invalid WebSocket data frame error
4243
DataFrameError(&'static str),
44+
/// Received unexpected status code
45+
StatusCodeError(StatusCode),
4346
/// No data available
4447
NoDataAvailable,
4548
/// An input/output error
@@ -90,6 +93,7 @@ impl Error for WebSocketError {
9093
WebSocketError::TlsHandshakeInterruption => "TLS Handshake interrupted",
9194
WebSocketError::Utf8Error(_) => "UTF-8 failure",
9295
WebSocketError::WebSocketUrlError(_) => "WebSocket URL failure",
96+
WebSocketError::StatusCodeError(_) => "Received unexpected status code",
9397
}
9498
}
9599

0 commit comments

Comments
 (0)