From fef9efe4d40d73aa58be28215709e560f01bc09c Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Sun, 30 Jun 2024 21:36:06 +0200 Subject: [PATCH] Less agressive push towards the login page on errors --- .../ngax/scripts/services/AppService.js | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/Duplicati/Server/webroot/ngax/scripts/services/AppService.js b/Duplicati/Server/webroot/ngax/scripts/services/AppService.js index 06171d343..b3eeefdad 100644 --- a/Duplicati/Server/webroot/ngax/scripts/services/AppService.js +++ b/Duplicati/Server/webroot/ngax/scripts/services/AppService.js @@ -48,42 +48,30 @@ backupApp.service('AppService', function ($http, $cookies, $q, $cookies, DialogS response => { if (response.status == 401) { - - // Most likely, the access token has expired - // Calling refresh should get us a new token, but we may already be trying to get a new token - if (self.access_token != null || (self.access_token == null && self.access_token_promise != null)) { - // If we have a token, we should remove it and obtain a new one - if (self.access_token != null) { - self.access_token = null; - self.access_token_promise = null; - } - - // If we are already getting a token, this call will return a shared promise - self.getAccessToken().then( - () => { - // Got a new token, retry the operation - promiseAction().then( - response2 => deferred.resolve(response2), - response2 => { - loginRequired(); - deferred.reject(response2); - } - ); - }, - () => { - // Fail, but report the original failed response, not the refresh response - loginRequired(); - deferred.reject(response); - } - ); - - return; + // If we have a token, we should remove it and obtain a new one + if (self.access_token != null) { + self.access_token = null; + self.access_token_promise = null; } - // Not logged in for some reason - loginRequired(); - deferred.reject(response); + // If we are already getting a token, this call will return a shared promise + self.getAccessToken().then( + () => { + // Got a new token, retry the operation + promiseAction().then( + response2 => deferred.resolve(response2), + response2 => { + deferred.reject(response2); + } + ); + }, + () => { + // Fail, but report the original failed response, not the refresh response + deferred.reject(response); + } + ); + } else { // Non-authentication error deferred.reject(response); @@ -113,9 +101,14 @@ backupApp.service('AppService', function ($http, $cookies, $q, $cookies, DialogS self.access_token_promise = null; deferred.resolve(self.access_token); }, function (response) { + // Failed to get a new token, clear the old one self.access_token = null; self.access_token_promise = null; - loginRequired(); + + // Auth error, refresh token invalid + if (response.status == 401) + loginRequired(); + deferred.reject(response); });