1use std::fmt;
4
5#[derive(Debug, thiserror::Error)]
7pub enum HandlerError {
8 #[error("IO error: {0}")]
9 Io(#[from] std::io::Error),
10
11 #[error("Parse error: {0}")]
12 Parse(String),
13
14 #[error("Execution error: {0}")]
15 Execution(String),
16
17 #[error("Network error: {0}")]
18 Network(String),
19
20 #[error("Configuration error: {0}")]
21 Config(String),
22
23 #[error("Storage error: {0}")]
24 Storage(String),
25
26 #[error("WebSocket error: {0}")]
27 WebSocket(String),
28
29 #[cfg(feature = "wasm")]
30 #[error("WASM error: {0}")]
31 Wasm(String),
32
33 #[error("Unknown error: {0}")]
34 Unknown(String),
35}
36
37pub type Result<T> = std::result::Result<T, HandlerError>;
38
39#[cfg(feature = "wasm")]
40impl From<wasm_bindgen::JsValue> for HandlerError {
41 fn from(value: wasm_bindgen::JsValue) -> Self {
42 HandlerError::Wasm(format!("{:?}", value))
43 }
44}
45
46#[cfg(feature = "server")]
47impl From<hyper::Error> for HandlerError {
48 fn from(err: hyper::Error) -> Self {
49 HandlerError::Network(err.to_string())
50 }
51}