From 574e8f01356e51f5b9641d2fd8cf5d926930f6a2 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 23 Apr 2024 13:04:48 +1000 Subject: [PATCH] Show error message when turbo:frame-missing Instead of replacing frame contents with unhelpful text 'Content missing'. --- app/webpacker/js/turbo.js | 14 ++++++++++++++ app/webpacker/packs/admin.js | 3 ++- app/webpacker/packs/application.js | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 app/webpacker/js/turbo.js diff --git a/app/webpacker/js/turbo.js b/app/webpacker/js/turbo.js new file mode 100644 index 0000000000..4451810c93 --- /dev/null +++ b/app/webpacker/js/turbo.js @@ -0,0 +1,14 @@ +import "@hotwired/turbo"; + +document.addEventListener("turbo:frame-missing", (event) => { + // don't replace frame contents + event.preventDefault(); + + // show error message instead + status = event.detail.response.status; + if(status == 401) { + alert(I18n.t("errors.unauthorized.message")); + } else { + alert(I18n.t("errors.general_error.message")); + } +}); diff --git a/app/webpacker/packs/admin.js b/app/webpacker/packs/admin.js index 81735d3040..dbb68bafc2 100644 --- a/app/webpacker/packs/admin.js +++ b/app/webpacker/packs/admin.js @@ -1,6 +1,6 @@ import "controllers"; import "channels"; -import "@hotwired/turbo"; +import "../js/turbo"; import "../js/hotkeys"; import "../js/mrujs"; import "../js/matomo"; @@ -17,3 +17,4 @@ import Trix from "trix"; document.addEventListener("trix-file-accept", (event) => { event.preventDefault(); }); + diff --git a/app/webpacker/packs/application.js b/app/webpacker/packs/application.js index 5ee6a3b066..f8263d1830 100644 --- a/app/webpacker/packs/application.js +++ b/app/webpacker/packs/application.js @@ -1,5 +1,5 @@ import "controllers"; -import "@hotwired/turbo"; +import "../js/turbo"; import "../js/hotkeys"; import "../js/mrujs"; import "../js/matomo";