diff --git a/apps/dashboard/app/javascript/turbo_shim.js b/apps/dashboard/app/javascript/turbo_shim.js index 17494d296..4c12a473a 100644 --- a/apps/dashboard/app/javascript/turbo_shim.js +++ b/apps/dashboard/app/javascript/turbo_shim.js @@ -6,6 +6,7 @@ */ import { setInnerHTML } from './utils'; +import { alert } from './alert'; export function replaceHTML(id, html) { const ele = document.getElementById(id); @@ -24,7 +25,15 @@ export function replaceHTML(id, html) { export function pollAndReplace(url, delay, id, callback) { fetch(url, { headers: { Accept: "text/vnd.turbo-stream.html" } }) - .then(response => response.ok ? Promise.resolve(response) : Promise.reject(response.text())) + .then((response) => { + if(response.status == 200) { + return Promise.resolve(response); + } else if(response.status == 401) { + return Promise.reject("This page cannot update becase you are no longer authenticated. Please refresh the page to log back in.") + } else { + return Promise.reject(response.text()); + } + }) .then((r) => r.text()) .then((html) => replaceHTML(id, html)) .then(() => { @@ -34,7 +43,11 @@ export function pollAndReplace(url, delay, id, callback) { } }) .catch((err) => { - console.log('Cannot retrieve partial due to error:'); + if (typeof err == 'string') { + alert(err); + } else { + alert('This page has encountered an unexpected error. Please refresh the page.'); + } console.log(err); }); }