This should only be used to handle opaque exceptions thrown by the `fetch` call.
(value: JsValue)
| 35 | |
| 36 | /// This should only be used to handle opaque exceptions thrown by the `fetch` call. |
| 37 | pub(crate) fn string_from_fetch_error(value: JsValue) -> String { |
| 38 | value.as_string().unwrap_or_else(|| { |
| 39 | // TypeError means that this is an opaque `network error`, as defined by the spec: |
| 40 | // https://fetch.spec.whatwg.org/ |
| 41 | if value.has_type::<js_sys::TypeError>() { |
| 42 | web_sys::console::error_1(&value); |
| 43 | "Failed to fetch, check the developer console for details".to_owned() |
| 44 | } else { |
| 45 | format!("{value:#?}") |
| 46 | } |
| 47 | }) |
| 48 | } |
| 49 | |
| 50 | pub(crate) async fn fetch_base(request: &Request) -> Result<web_sys::Response, JsValue> { |
| 51 | let opts = web_sys::RequestInit::new(); |