sz_orm_websocket/
error.rs1use std::fmt;
2
3#[derive(Debug)]
4pub enum WsError {
5 Connection(String),
6 Message(String),
7 Authentication(String),
8 Channel(String),
9 Protocol(String),
10}
11
12impl fmt::Display for WsError {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 WsError::Connection(msg) => write!(f, "Connection error: {}", msg),
16 WsError::Message(msg) => write!(f, "Message error: {}", msg),
17 WsError::Authentication(msg) => write!(f, "Authentication error: {}", msg),
18 WsError::Channel(msg) => write!(f, "Channel error: {}", msg),
19 WsError::Protocol(msg) => write!(f, "Protocol error: {}", msg),
20 }
21 }
22}
23
24impl std::error::Error for WsError {}
25
26impl From<std::io::Error> for WsError {
27 fn from(err: std::io::Error) -> Self {
28 WsError::Connection(err.to_string())
29 }
30}
31
32impl From<serde_json::Error> for WsError {
33 fn from(err: serde_json::Error) -> Self {
34 WsError::Message(err.to_string())
35 }
36}