1use std::fmt;
3use wasm_bindgen::JsValue;
4
5#[derive(Debug)]
9pub enum Error {
10 Json(serde_json::Error),
12
13 Js(String),
15
16 Http(reqwest::Error),
18
19 DeserializeAssets(Box<bincode::ErrorKind>),
21
22 InvalidHeaderValue(String),
24
25 NoStaticAsset(String),
27
28 #[allow(clippy::upper_case_acronyms)]
30 KVKeyNotFound(String, u16),
31
32 #[allow(clippy::upper_case_acronyms)]
34 KVApi(reqwest::Error),
35
36 Other(String),
38}
39
40impl std::error::Error for Error {}
41unsafe impl Send for Error {}
42
43impl From<String> for Error {
44 fn from(msg: String) -> Error {
45 Error::Other(msg)
46 }
47}
48
49impl From<serde_json::Error> for Error {
50 fn from(e: serde_json::Error) -> Self {
51 Error::Json(e)
52 }
53}
54
55impl From<reqwest::Error> for Error {
56 fn from(e: reqwest::Error) -> Self {
57 Error::Http(e)
58 }
59}
60
61impl From<JsValue> for Error {
62 fn from(e: JsValue) -> Self {
63 Error::Js(
64 e.as_string()
65 .unwrap_or_else(|| "Javascript error".to_string()),
66 )
67 }
68}
69
70impl fmt::Display for Error {
71 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72 write!(f, "{:?}", self)
73 }
74}