Skip to content

Commit 3993db2

Browse files
committed
frontend: suppress failed to fetch error.
1 parent 37ef203 commit 3993db2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

frontend/src/components/Alert.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const clearAlertTimeout = (id: string) => {
2020
};
2121

2222
export function showAlert(text: string, variant: "danger" | "success" | "warning", id?: string, heading?: string, timeout_ms?: number) {
23+
if (text.indexOf("Failed to fetch") !== -1) {
24+
console.warn("Alert suppressed due to 'Failed to fetch' message");
25+
return;
26+
}
27+
2328
id = id ? id : Math.random().toString(36).substr(2);
2429
const alert: AlertItem = {
2530
id,

frontend/src/worker.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ const tunnel_url = `${import.meta.env.VITE_BACKEND_WS_URL }/ws?key_id=`
2727
let wgClient: Client | undefined;
2828
let setup_data: SetupMessage;
2929

30+
function isFailedToFetch(reason: unknown): boolean {
31+
if (!reason) return false;
32+
if (typeof reason === 'string') return reason.includes('Failed to fetch');
33+
if (reason instanceof Error) return reason.message.includes('Failed to fetch');
34+
return false;
35+
}
36+
3037
self.addEventListener("unhandledrejection", (event) => {
38+
if (isFailedToFetch(event.reason)) {
39+
event.preventDefault();
40+
return;
41+
}
42+
3143
const stack = event.reason.stack.split("\n");
3244

3345
const evt = {

0 commit comments

Comments
 (0)