simple_websocket/
error.rs1use crate::frame::Frame;
2use std::io;
3use std::string::FromUtf8Error;
4use thiserror::Error;
5use tokio::sync::mpsc::error::SendError;
6use tokio::time::error::Elapsed;
7
8#[derive(Error, Debug)]
9pub enum CloseError {
10 #[error("{source}")]
11 SendError {
12 #[from]
13 source: SendError<Frame>,
14 },
15
16 #[error("{source}")]
17 Timeout {
18 #[from]
19 source: Elapsed,
20 },
21}
22
23#[derive(Error, Debug)]
24pub enum HandshakeError {
25 #[error("Couldn't find Sec-WebSocket-Key header in the request")]
26 NoSecWebsocketKey,
27
28 #[error("IO Error happened: {source}")]
29 IOError {
30 #[from]
31 source: io::Error,
32 },
33
34 #[error("{source}")]
35 FromUtf8Error {
36 #[from]
37 source: FromUtf8Error,
38 },
39
40 #[error("Server didn't upgrade the connection")]
41 NoUpgrade,
42
43 #[error("Sever didn't send a valid Sec-WebSocket-Accept key")]
44 InvalidAcceptKey,
45}
46
47#[derive(Error, Debug)]
48pub enum StreamError {
49 #[error("{source}")]
50 IOError {
51 #[from]
52 source: io::Error,
53 },
54
55 #[error("channel communication error")]
56 CommunicationError,
57
58 #[error("{source}")]
59 InternalSendError {
60 #[from]
61 source: SendError<Frame>,
62 },
63
64 #[error("{source}")]
65 CloseChannelError {
66 #[from]
67 source: SendError<bool>,
68 },
69
70 #[error("Incoming fragmented message but there is one already in progress")]
71 FragmentedInProgress,
72
73 #[error("Invalid continuation frame: no fragmented message to continue")]
74 InvalidContinuationFrame,
75}