use native_tls::Error as NativeTlsError;
use std::io::Error as IoError;
use thiserror::Error;
use url::ParseError;
#[derive(Error, Debug)]
pub enum WebSocketError {
#[error("could not connect using TCP")]
TcpConnectionError(IoError),
#[error("could not connect using TLS")]
TlsConnectionError(NativeTlsError),
#[error("could not build WebSocket with given TLS configuration")]
TlsBuilderError(NativeTlsError),
#[error("error with TLS configuration")]
TlsConfigurationError(NativeTlsError),
#[error("websocket is already closed")]
WebSocketClosedError,
#[error("error shutting down stream")]
ShutdownError(IoError),
#[error("invalid handshake response")]
InvalidHandshakeError,
#[error("server rejected handshake")]
HandshakeFailedError {
status_code: String,
headers: Vec<(String, String)>,
body: Option<String>,
},
#[error("control frame has payload larger than 125 bytes")]
ControlFrameTooLargeError,
#[error("payload is too large")]
PayloadTooLargeError,
#[error("received frame is invalid")]
InvalidFrameError,
#[error("received masked frame")]
ReceivedMaskedFrameError,
#[error("url could not be parsed")]
ParseError(ParseError),
#[error(r#"invalid websocket scheme (use "ws" or "wss")"#)]
SchemeError,
#[error("invalid or missing host")]
HostError,
#[error("invalid or unknown port")]
PortError,
#[error("could not parse into SocketAddrs")]
SocketAddrError(IoError),
#[error("could not resolve domain")]
ResolutionError,
#[error("could not read from WebSocket")]
ReadError(IoError),
#[error("could not write to WebSocket")]
WriteError(IoError),
#[error("error using channel")]
ChannelError,
}