use thiserror::Error as ThisError;
use wasm_bindgen::JsValue;
#[derive(Debug, ThisError)]
pub enum Error {
#[error("Cannot find Window object")]
MissingWindow,
#[error("{context}")]
WebSys {
context: String,
#[source]
source: WebError,
},
}
#[derive(Debug, ThisError)]
#[error("{0}")]
pub struct WebError(String);
impl Error {
pub(crate) fn web<S>(context: S, error: JsValue) -> Error
where
S: Into<String>,
{
let error = if let Some(error) = error.as_string() { error } else { format!("{:?}", error) };
Self::WebSys { context: context.into(), source: WebError(error) }
}
}