v3: misc fixes for payments

This commit is contained in:
Matteo Pagliazzi
2016-05-18 22:35:03 +02:00
parent 9efe75e9b8
commit 65c739f7de
10 changed files with 23 additions and 14 deletions

View File

@@ -3,6 +3,9 @@
angular.module('habitrpg')
.config(['$httpProvider', function($httpProvider){
$httpProvider.interceptors.push(['$q', '$rootScope', function($q, $rootScope){
var resyncNumber = 0;
var lastResync = 0;
return {
response: function(response) {
return response;
@@ -41,7 +44,13 @@ angular.module('habitrpg')
$rootScope.$broadcast('responseError', response.data.message);
}
if ($rootScope.User && $rootScope.User.sync) $rootScope.User.sync();
if ($rootScope.User && $rootScope.User.sync) {
if (resyncNumber < 100 && (Date.now() - lastResync) > 500) { // avoid thousands of requests when user is not found
$rootScope.User.sync();
resyncNumber++;
lastResync = Date.now();
}
}
// Need to reject the prompse so the error is handled correctly
if (response.status === 401) {