1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use gloo_utils::errors::JsError;
use wasm_bindgen::{JsCast, JsValue};
#[derive(Debug, thiserror::Error)]
pub enum StorageError {
#[error("{0}")]
SerdeError(#[from] serde_json::Error),
#[error("key {0} not found")]
KeyNotFound(String),
#[error("{0}")]
JsError(JsError),
}
pub(crate) fn js_to_error(js_value: JsValue) -> StorageError {
match js_value.dyn_into::<js_sys::Error>() {
Ok(error) => StorageError::JsError(JsError::from(error)),
Err(_) => unreachable!("JsValue passed is not an Error type - this is a bug"),
}
}