Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions apps/rustgis-web/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::rc::Rc;

use rustgis_ui_egui::rustgis_engine::{data::diagnostics::Capture, sources::message_with_address};
use rustgis_ui_egui::rustgis_engine::{
data::diagnostics::{
Capture,
fetch_reason::{BROWSER_UNREACHABLE, LARGER_THAN, STALLED},
},
sources::message_with_address,
};
use rustgis_ui_egui::{FindChords, Inbox, RustGisApp, Services, Slot};

use crate::parts::Notes;
Expand Down Expand Up @@ -850,7 +856,7 @@ async fn fetch_reached(
let err = |e: wasm_bindgen::JsValue| {
if authenticated { "the browser couldn't process the authenticated request".to_string() } else { format!("{e:?}") }
};
let stalled = || format!("nothing came in {} seconds", STALL_MS / 1000);
let stalled = || format!("{STALLED} {} seconds", STALL_MS / 1000);
let result = async {
// A refused fetch is an opaque TypeError ("Failed to fetch") by design. Keep its message
// only on requests without a login: even a browser's error may repeat credentials.
Expand All @@ -867,7 +873,7 @@ async fn fetch_reached(
e.dyn_ref::<js_sys::Error>().map(|e| String::from(e.message())).unwrap_or_else(|| err(e))
};
format!(
"the browser couldn't reach it (offline, blocked by a browser extension or the network, or the server doesn't accept requests from web pages): {why}"
"{BROWSER_UNREACHABLE} (offline, blocked by a browser extension or the network, or the server doesn't accept requests from web pages): {why}"
)
})?
.dyn_into()
Expand Down Expand Up @@ -930,7 +936,7 @@ async fn fetch_reached(
if whole_tail.is_some() {
return Err(message_with_address(&url, cache::NO_RANGES));
}
return Err(format!("larger than {max} bytes"));
return Err(format!("{LARGER_THAN} {max} bytes"));
}
let at = bytes.len();
bytes.resize(at + n, 0);
Expand Down Expand Up @@ -1020,7 +1026,7 @@ async fn post_json(
let result = async {
let resp: web_sys::Response = wasm_bindgen_futures::JsFuture::from(promise)
.await
.map_err(|_| "the browser couldn't reach it (offline, or the server doesn't accept requests from web pages)".to_string())?
.map_err(|_| format!("{BROWSER_UNREACHABLE} (offline, or the server doesn't accept requests from web pages)"))?
.dyn_into()
.map_err(err)?;
diagnostics.answered(resp.status());
Expand Down Expand Up @@ -1121,7 +1127,7 @@ async fn head(
let result = async {
let resp: web_sys::Response = wasm_bindgen_futures::JsFuture::from(promise)
.await
.map_err(|_| "the browser couldn't reach it (offline, or the server doesn't accept requests from web pages)".to_string())?
.map_err(|_| format!("{BROWSER_UNREACHABLE} (offline, or the server doesn't accept requests from web pages)"))?
.dyn_into()
.map_err(err)?;
diagnostics.answered(resp.status());
Expand Down
13 changes: 13 additions & 0 deletions crates/data/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,19 @@ pub fn address_in_message(address: &str) -> String {
shown
}

/// Fixed fetch failure text that paging notices may retain from an address-bearing error.
pub mod fetch_reason {
pub const BROWSER_UNREACHABLE: &str = "the browser couldn't reach it";
pub const STALLED: &str = "nothing came in";
pub const LARGER_THAN: &str = "larger than";
pub const PAGES_TIMED_OUT: &str = "the pages timed out";
pub const ADDRESS_HAS_SPACES: &str = "the address has spaces in it";
pub const HTTP_ONLY: &str = "only http:// and https:// addresses are fetched";
pub const DOWNGRADE_REDIRECT: &str = "a redirect from https to http";
pub const FORBIDDEN_ADDRESS: &str = "that address is never fetched";
pub const PUBLIC_TO_LOCAL: &str = "a document on the web can't point into the local network";
}

/// Composes a known address and its failure reason without exposing credentials or swallowing
/// the reason after a secret query. Exact address occurrences (including unescaped whitespace)
/// are sanitized first; unrelated URLs and credential fields still use conservative [`redact`].
Expand Down
Loading
Loading