Skip to content

Commit

Permalink
feat(fetcher): return error messages from JS on WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Jan 3, 2025
1 parent c6fbd47 commit 0bd98b5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fetcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@ pub async fn fetch(request: Request, fetcher: &js_sys::Function) -> Result<Respo
FetcherError(
err
.as_string()
.unwrap_or("error calling the fetcher".into()),
// try to get the error message from the error object
.unwrap_or_else(|| js_sys::Error::from(err).to_string().into()),
)
})?);

let response = JsFuture::from(response).await.map_err(|err| {
FetcherError(
err
.as_string()
.unwrap_or("error during the fetcher promise".into()),
// try to get the error message from the error object
.unwrap_or_else(|| js_sys::Error::from(err).to_string().into()),
)
})?;

Expand Down

0 comments on commit 0bd98b5

Please sign in to comment.