Skip to content

Commit

Permalink
Update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
FlareLine committed Feb 2, 2023
1 parent 51a329e commit c725fcb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions worker/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,21 @@ impl std::fmt::Display for Error {

impl std::error::Error for Error {}

// Not sure if the changes I've made here are good or bad...
impl From<JsValue> for Error {
fn from(v: JsValue) -> Self {
match v
.as_string()
.or_else(|| v.dyn_ref::<js_sys::Error>().map(|e| e.to_string().into()))
{
match v.as_string().or_else(|| {
v.dyn_ref::<js_sys::Error>().map(|e| {
format!(
"Error: {} - Cause: {}",
e.to_string(),
e.cause()
.as_string()
.or_else(|| { Some(e.to_string().into()) })
.unwrap_or(String::from("N/A"))
)
})
}) {
Some(s) => Self::JsError(s),
None => Self::Internal(v),
}
Expand Down

0 comments on commit c725fcb

Please sign in to comment.