Prevent repeated account info calls when logged out

When an account info call is made, it is expected that it will
return a 403 error upon failure when logged out. Store the cached
value as null so that further calls will not hit the server
unnecessarily

Change-Id: If7a8d5e921dce3f09e7f91d82d384d70bb338ba8
This commit is contained in:
Andrew Bonventre
2016-06-07 11:56:38 -04:00
parent 2d50851a67
commit 1ec7b3f158

View File

@@ -209,7 +209,11 @@
},
getAccount: function() {
return this._fetchSharedCacheURL('/accounts/self/detail');
return this._fetchSharedCacheURL('/accounts/self/detail', function(resp) {
if (resp.status === 403) {
this._cache['/accounts/self/detail'] = null;
}
}.bind(this));
},
getLoggedIn: function() {
@@ -231,7 +235,7 @@
}.bind(this));
},
_fetchSharedCacheURL: function(url) {
_fetchSharedCacheURL: function(url, opt_errFn) {
if (this._sharedFetchPromises[url]) {
return this._sharedFetchPromises[url];
}
@@ -239,7 +243,7 @@
if (this._cache[url] !== undefined) {
return Promise.resolve(this._cache[url]);
}
this._sharedFetchPromises[url] = this.fetchJSON(url).then(
this._sharedFetchPromises[url] = this.fetchJSON(url, opt_errFn).then(
function(response) {
if (response !== undefined) {
this._cache[url] = response;