use wasm_bindgen::JsValue;
#[derive(Debug, PartialEq, Clone)]
pub enum FetchError {
DeserializeError { error: String, content: String },
ResponseError {
status_code: u16,
response_body: String,
},
TextNotAvailable,
CouldNotCreateFetchFuture,
CouldNotCreateRequest(JsValue), CouldNotSerializeRequestBody,
}
impl std::fmt::Display for FetchError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FetchError::DeserializeError { error, content } => f.write_str(&format!(
"Could not deserialize a successful request. With error: {}, and content: {}",
error, content
)),
FetchError::ResponseError {
status_code,
response_body,
} => f.write_str(&format!(
"The server returned a response with code: {}, and body: {}",
status_code, response_body
)),
FetchError::TextNotAvailable => {
f.write_str("The text could not be extracted from the response.")
}
FetchError::CouldNotCreateFetchFuture => {
f.write_str("Could not create a fetch future.")
}
FetchError::CouldNotCreateRequest(_) => {
f.write_str("Could not create a fetch request.")
}
FetchError::CouldNotSerializeRequestBody => {
f.write_str("Could not serialize the body in the fetch request.")
}
}
}
}
impl std::error::Error for FetchError {}