Show error message when turbo:frame-missing

Instead of replacing frame contents with unhelpful text 'Content missing'.
This commit is contained in:
David Cook
2024-04-23 13:04:48 +10:00
parent b5cdee3d65
commit 574e8f0135
3 changed files with 17 additions and 2 deletions

14
app/webpacker/js/turbo.js Normal file
View File

@@ -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"));
}
});

View File

@@ -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();
});

View File

@@ -1,5 +1,5 @@
import "controllers";
import "@hotwired/turbo";
import "../js/turbo";
import "../js/hotkeys";
import "../js/mrujs";
import "../js/matomo";