js: fix null xhr in autosave error handling

Sentry reports many cases of the xhr object being missing in the
error handler.

Ensure the error handling code doesn't crash because of the missing xhr.
This commit is contained in:
Pierre de La Morinerie 2021-08-31 14:54:02 -05:00
parent b709a160fc
commit 7380d27d78

View file

@ -64,7 +64,7 @@ addEventListener('autosave:end', () => {
addEventListener('autosave:error', (event) => {
let error = event.detail;
if (error.xhr.status == 401) {
if (error.xhr && error.xhr.status == 401) {
// If we are unauthenticated, reload the page using a GET request.
// This will allow Devise to properly redirect us to sign-in, and then back to this page.
document.location.reload();