Skip to content

Commit 7f8f877

Browse files
authored
Merge pull request #234 from jean-airoldie/status_code_error
Added StatusCodeError when receiving unexpected status code
2 parents db355c6 + f1ad464 commit 7f8f877

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
@@ -855,9 +855,7 @@ impl<'u> ClientBuilder<'u> {
855855
let status = StatusCode::from_u16(response.subject.0);
856856

857857
if status != StatusCode::SwitchingProtocols {
858-
return Err(WebSocketError::ResponseError(
859-
"Status code must be Switching Protocols",
860-
));
858+
return Err(WebSocketError::StatusCodeError(status));
861859
}
862860

863861
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)