wasm_webauthn/
error.rs

1use std::string::FromUtf8Error;
2
3use coset::CoseError;
4use thiserror::Error;
5use wasm_bindgen::JsValue;
6use web_sys::console;
7
8pub type Result<T> = std::result::Result<T, Error>;
9
10#[derive(Debug, Error)]
11pub enum Error {
12    #[error("{0}")]
13    Serialize(#[from] serde_wasm_bindgen::Error),
14    #[error("{0}")]
15    Deserialize(#[from] ciborium::de::Error<std::io::Error>),
16    #[error("failed to access context")]
17    ContextUnavailable,
18    #[error("{0}")]
19    WebSys(String),
20    #[error("{0}")]
21    Cose(#[from] CoseError),
22    #[error("{0}")]
23    Io(#[from] std::io::Error),
24    #[error("{0}")]
25    Utf8(#[from] FromUtf8Error),
26}
27
28impl From<JsValue> for Error {
29    fn from(value: JsValue) -> Self {
30        if let Some(message) = value.as_string() {
31            Self::WebSys(message)
32        } else {
33            console::log_1(&value);
34            Self::WebSys("Unknown".into())
35        }
36    }
37}