Skip to content

Commit

Permalink
Adding error variants for the violence page
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephLai241 committed Jan 13, 2024
1 parent 4d268a7 commit bb21b10
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions frontend/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,38 @@

use thiserror::Error;
use wasm_bindgen::JsValue;
use web_sys::{Element, HtmlTableElement};

/// Contains all error variants that may be raised.
#[derive(Debug, Error)]
pub enum StaccError {
/// Something fucked up while setting the background GIF.
#[error("Could not modify the document.body style: {0:#?}")]
SetBackgroundError(JsValue),
/// Something fucked up while interacting with `Element`s.
#[error("Element error: {0:#?}")]
ElementError(Element),

/// Something fucked up while interacting with `HtmlTableElement`s.
#[error("HtmlTableElement error: {0:#?}")]
HtmlTableElementError(HtmlTableElement),

/// Something fucked up while interacting with `JsValue`s.
#[error("JsValue error: {0:#?}")]
JsValueError(JsValue),
}

impl From<Element> for StaccError {
fn from(element: Element) -> Self {
StaccError::ElementError(element)
}
}

impl From<HtmlTableElement> for StaccError {
fn from(html_table_element: HtmlTableElement) -> Self {
StaccError::HtmlTableElementError(html_table_element)
}
}

impl From<JsValue> for StaccError {
fn from(js_value: JsValue) -> Self {
StaccError::SetBackgroundError(js_value)
StaccError::JsValueError(js_value)
}
}

0 comments on commit bb21b10

Please sign in to comment.