Преглед изворни кода

Merge pull request #2841 from overleaf/as-fix-system-message-redirect

Fix system messages breaking when user logs out

GitOrigin-RevId: 10cce5466fed407469964db7caa4628e9c0536a3
Simon Detheridge пре 6 година
родитељ
комит
f159b2ee47
1 измењених фајлова са 15 додато и 2 уклоњено
  1. 15 2
      services/web/frontend/js/main/system-messages.js

+ 15 - 2
services/web/frontend/js/main/system-messages.js

@@ -13,12 +13,25 @@ import App from '../base'
 const MESSAGE_POLL_INTERVAL = 15 * 60 * 1000
 const MESSAGE_POLL_INTERVAL = 15 * 60 * 1000
 // Controller for messages (array)
 // Controller for messages (array)
 App.controller('SystemMessagesController', ($http, $scope) => {
 App.controller('SystemMessagesController', ($http, $scope) => {
-  $scope.messages = window.systemMessages
+  $scope.messages = []
   var pollSystemMessages = function() {
   var pollSystemMessages = function() {
+    // Ignore polling if tab is hidden or browser is offline
+    if (document.hidden || !navigator.onLine) {
+      return
+    }
+
     $http
     $http
       .get('/system/messages')
       .get('/system/messages')
       .then(response => {
       .then(response => {
-        $scope.messages = response.data
+        // Ignore if content-type is anything but JSON, prevents a bug where
+        // the user logs out in another tab, then a 302 redirect was returned,
+        // which is transparently resolved by the browser to the login (HTML)
+        // page.
+        // This then caused an Angular error where it was attempting to loop
+        // through the HTML as a string
+        if (response.headers('content-type').includes('json')) {
+          $scope.messages = response.data
+        }
       })
       })
       .catch(() => {
       .catch(() => {
         // ignore errors
         // ignore errors