diff --git a/public/js/app.js b/public/js/app.js index 3f2aae2a08..810dbc8367 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -234,8 +234,12 @@ window.habitrpg = angular.module('habitrpg', window.location.href = '/logout'; // 400 range? - } else if (response < 500) { + } else if (response.status < 500) { $rootScope.$broadcast('responseText', response.data.err || response.data); + // Need to reject the prompse so the error is handled correctly + if (response.status === 401) { + return $q.reject(response); + } // Error } else { diff --git a/public/js/controllers/rootCtrl.js b/public/js/controllers/rootCtrl.js index b990050ef5..1582aecaae 100644 --- a/public/js/controllers/rootCtrl.js +++ b/public/js/controllers/rootCtrl.js @@ -124,8 +124,8 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$ $scope.$apply(function(){ $http.post(url, data).success(function() { window.location.reload(true); - }).error(function(err) { - alert(err); + }).error(function(data) { + alert(data.err); }); }) } @@ -144,8 +144,8 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$ $scope.$apply(function(){ $http.post(url, data).success(function() { window.location.reload(true); - }).error(function(err) { - alert(err); + }).error(function(data) { + alert(data.err); }); }) } diff --git a/public/js/controllers/settingsCtrl.js b/public/js/controllers/settingsCtrl.js index 9b474d8bab..a6c401d179 100644 --- a/public/js/controllers/settingsCtrl.js +++ b/public/js/controllers/settingsCtrl.js @@ -23,7 +23,7 @@ habitrpg.controller('SettingsCtrl', window.location.reload(); }); } - } + } $scope.toggleStickyHeader = function(){ $rootScope.$on('userSynced', function(){ @@ -85,7 +85,7 @@ habitrpg.controller('SettingsCtrl', $scope.changeUser = {}; }) .error(function(data){ - alert(data); + alert(data.err); }); } @@ -94,12 +94,13 @@ habitrpg.controller('SettingsCtrl', return alert(window.env.t('fillAll')); } $http.post(API_URL + '/api/v2/user/change-password', changePass) - .success(function(){ + .success(function(data, status, headers, config){ + if (data.err) return alert(data.err); alert(window.env.t('passSuccess')); $scope.changePass = {}; }) - .error(function(data){ - alert(data); + .error(function(data, status, headers, config){ + alert(data.err); }); }