From a9dc6017511b9a4ab98e701f46b1a11d83dec6e2 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sun, 4 Aug 2024 21:57:17 +0100 Subject: [PATCH] web: fix intermittent "coudln't connect" on page load was caused by language selector loader, simply added a "noConnectionError" param to the _get/_post... methods which is enabled for it. --- ts/modules/common.ts | 12 ++++++------ ts/modules/lang.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ts/modules/common.ts b/ts/modules/common.ts index f04a57e..208be19 100644 --- a/ts/modules/common.ts +++ b/ts/modules/common.ts @@ -21,7 +21,7 @@ export function toDateString(date: Date): string { return date.toLocaleDateString(locale, args1) + " " + date.toLocaleString(locale, args2); } -export const _get = (url: string, data: Object, onreadystatechange: (req: XMLHttpRequest) => void): void => { +export const _get = (url: string, data: Object, onreadystatechange: (req: XMLHttpRequest) => void, noConnectionError: boolean = false): void => { let req = new XMLHttpRequest(); if (window.URLBase) { url = window.URLBase + url; } req.open("GET", url, true); @@ -30,7 +30,7 @@ export const _get = (url: string, data: Object, onreadystatechange: (req: XMLHtt req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); req.onreadystatechange = () => { if (req.status == 0) { - window.notifications.connectionError(); + if (!noConnectionError) window.notifications.connectionError(); return; } else if (req.status == 401) { window.notifications.customError("401Error", window.lang.notif("error401Unauthorized")); @@ -65,7 +65,7 @@ export const _upload = (url: string, formData: FormData): void => { req.send(formData); }; -export const _post = (url: string, data: Object, onreadystatechange: (req: XMLHttpRequest) => void, response?: boolean, statusHandler?: (req: XMLHttpRequest) => void): void => { +export const _post = (url: string, data: Object, onreadystatechange: (req: XMLHttpRequest) => void, response?: boolean, statusHandler?: (req: XMLHttpRequest) => void, noConnectionError: boolean = false): void => { let req = new XMLHttpRequest(); req.open("POST", window.URLBase + url, true); if (response) { @@ -76,7 +76,7 @@ export const _post = (url: string, data: Object, onreadystatechange: (req: XMLHt req.onreadystatechange = () => { if (statusHandler) { statusHandler(req); } else if (req.status == 0) { - window.notifications.connectionError(); + if (!noConnectionError) window.notifications.connectionError(); return; } else if (req.status == 401) { window.notifications.customError("401Error", window.lang.notif("error401Unauthorized")); @@ -86,14 +86,14 @@ export const _post = (url: string, data: Object, onreadystatechange: (req: XMLHt req.send(JSON.stringify(data)); }; -export function _delete(url: string, data: Object, onreadystatechange: (req: XMLHttpRequest) => void): void { +export function _delete(url: string, data: Object, onreadystatechange: (req: XMLHttpRequest) => void, noConnectionError: boolean = false): void { let req = new XMLHttpRequest(); req.open("DELETE", window.URLBase + url, true); req.setRequestHeader("Authorization", "Bearer " + window.token); req.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); req.onreadystatechange = () => { if (req.status == 0) { - window.notifications.connectionError(); + if (!noConnectionError) window.notifications.connectionError(); return; } else if (req.status == 401) { window.notifications.customError("401Error", window.lang.notif("error401Unauthorized")); diff --git a/ts/modules/lang.ts b/ts/modules/lang.ts index 149e672..1927974 100644 --- a/ts/modules/lang.ts +++ b/ts/modules/lang.ts @@ -88,5 +88,5 @@ export const loadLangSelector = (page: string) => { } list.innerHTML = innerHTML; } - }); + }, true); };