diff --git a/crates/bitwarden-wasm-internal/src/client.rs b/crates/bitwarden-wasm-internal/src/client.rs index ac7779b2f..0a5ce27d5 100644 --- a/crates/bitwarden-wasm-internal/src/client.rs +++ b/crates/bitwarden-wasm-internal/src/client.rs @@ -49,6 +49,10 @@ impl BitwardenClient { msg } + pub fn throw(&self, msg: String) -> Result<(), crate::error::GenericError> { + Err(crate::error::GenericError(msg)) + } + /// Test method, calls http endpoint pub async fn http_get(&self, url: String) -> Result { let client = self.0.internal.get_http_client(); diff --git a/crates/bitwarden-wasm-internal/src/error.js b/crates/bitwarden-wasm-internal/src/error.js deleted file mode 100644 index cd3d3a346..000000000 --- a/crates/bitwarden-wasm-internal/src/error.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Error thrown by the WASM module. - * @param {string} message - Error message. - * @extends Error - */ -class WasmError extends Error { - constructor(message) { - super(message); - this.name = "WasmError"; - } -} - -exports.WasmError = WasmError; diff --git a/crates/bitwarden-wasm-internal/src/error.rs b/crates/bitwarden-wasm-internal/src/error.rs index 2750d2629..237ee4941 100644 --- a/crates/bitwarden-wasm-internal/src/error.rs +++ b/crates/bitwarden-wasm-internal/src/error.rs @@ -2,12 +2,13 @@ use wasm_bindgen::prelude::*; // Importing an error class defined in JavaScript instead of defining it in Rust // allows us to extend the `Error` class. It also provides much better console output. -#[wasm_bindgen(module = "/src/error.js")] +#[wasm_bindgen] extern "C" { - type WasmError; + #[wasm_bindgen(js_name = Error)] + type JsError; - #[wasm_bindgen(constructor)] - fn new(message: String) -> WasmError; + #[wasm_bindgen(constructor, js_class = Error)] + fn new(message: String) -> JsError; } pub type Result = std::result::Result; @@ -22,6 +23,6 @@ impl From for GenericError { impl From for JsValue { fn from(error: GenericError) -> Self { - WasmError::new(error.0).into() + JsError::new(error.0).into() } }