fix(ujs-error-handling): sometimes body is not yet ready,other calls regarding ajax namespace are wired on document, copy/paste

This commit is contained in:
Martin 2022-07-19 09:50:55 +02:00 committed by mfo
parent 40df4bee84
commit 850f9375b7

View file

@ -1,6 +1,6 @@
// For links and requests done through rails-ujs (mostly data-remote links),
// redirect to the sign-in page when the server responds '401 Unauthorized'.
document.body.addEventListener('ajax:error', (event) => {
document.addEventListener('ajax:error', (event) => {
const [, , xhr] = event.detail;
if (xhr && xhr.status == 401) {
location.reload(); // reload whole page so Devise will redirect to sign-in