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

Fix system messages breaking when user logs out

GitOrigin-RevId: 10cce5466fed407469964db7caa4628e9c0536a3
This commit is contained in:
Simon Detheridge 2020-05-22 12:16:42 +01:00 committed by Copybot
parent 4c88a83332
commit f159b2ee47

View file

@ -13,12 +13,25 @@ import App from '../base'
const MESSAGE_POLL_INTERVAL = 15 * 60 * 1000
// Controller for messages (array)
App.controller('SystemMessagesController', ($http, $scope) => {
$scope.messages = window.systemMessages
$scope.messages = []
var pollSystemMessages = function() {
// Ignore polling if tab is hidden or browser is offline
if (document.hidden || !navigator.onLine) {
return
}
$http
.get('/system/messages')
.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(() => {
// ignore errors