use crate::frame::Frame;
use std::io;
use std::string::FromUtf8Error;
use thiserror::Error;
use tokio::sync::mpsc::error::SendError;
use tokio::time::error::Elapsed;
use url::ParseError;
#[derive(Error, Debug)]
pub enum Error {
#[error("{source}")]
SendError {
#[from]
source: SendError<Frame>,
},
#[error("channel communication error")]
CommunicationError,
#[error("{source}")]
Timeout {
#[from]
source: Elapsed,
},
#[error("IO Error happened: {source}")]
IOError {
#[from]
source: io::Error,
},
#[error("{source}")]
FromUtf8Error {
#[from]
source: FromUtf8Error,
},
#[error("Couldn't find Sec-WebSocket-Key header in the request")]
NoSecWebsocketKey,
#[error("Server didn't upgrade the connection")]
NoUpgrade,
#[error("Sever didn't send a valid Sec-WebSocket-Accept key")]
InvalidAcceptKey,
#[error("RSV not zero")]
RSVNotZero,
#[error("Control frames must not be fragmented")]
ControlFramesFragmented,
#[error("Control frame with invalid payload size, can be greater than 125")]
ControlFramePayloadSize,
#[error("Payload too large")]
PayloadSize,
#[error("Invalid frame while there is a fragmented message in progress")]
InvalidFrameFragmentation,
#[error("Incoming fragmented message but there is one already in progress")]
FragmentedInProgress,
#[error("Invalid continuation frame: no fragmented message to continue")]
InvalidContinuationFrame,
#[error("Invalid Opcode")]
InvalidOpcode,
#[error("{source}")]
URLParseError {
#[from]
source: ParseError,
},
#[error("Invalid scheme in WebSocket URL")]
InvalidSchemeURL,
#[error("URL has no host")]
URLNoHost,
#[error("URL has no port")]
URLNoPort,
}