global error handling
Change-Id: Ic898478157857fc15c91c8fdb30d122acdf5f44b
This commit is contained in:
parent
03f6c7610a
commit
87a4a2f6a6
@ -36,7 +36,25 @@
|
||||
<div ui-view></div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
<script type="text/ng-template" id="messagemodal.html">
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-title">
|
||||
<i class="ace-icon fa fa-exclamation-triangle orange"></i>
|
||||
Error {{status}}
|
||||
</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<span ng-if="warning.message">
|
||||
{{warning.message}}
|
||||
</span>
|
||||
<span ng-if="warning.message === undefined">
|
||||
Error occured.
|
||||
</span>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-primary" ng-click="ok()">OK</button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
</html>
|
||||
|
@ -45,10 +45,15 @@ define([
|
||||
});
|
||||
compassModule.run(function($rootScope, $state, authService, rememberMe) {
|
||||
$rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) {
|
||||
if (toState.authenticate && rememberMe.getCookie('isAuthenticated') != "true") {
|
||||
// User isn't authenticated
|
||||
$state.transitionTo("login");
|
||||
event.preventDefault();
|
||||
if (toState.authenticate && !authService.isAuthenticated) {
|
||||
if (rememberMe.getCookie("isAuthenticated")) {
|
||||
authService.isAuthenticated = true
|
||||
}
|
||||
else {
|
||||
// User isn't authenticated
|
||||
$state.transitionTo("login");
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -65,7 +70,7 @@ define([
|
||||
|
||||
$scope.logout = function() {
|
||||
authService.logout().success(function(data) {
|
||||
rememberMe.setCookies("isAuthenticated", "false", -30);
|
||||
authService.setLogout();
|
||||
$state.transitionTo("login");
|
||||
}).error(function(response) {
|
||||
console.log(response);
|
||||
@ -73,5 +78,13 @@ define([
|
||||
})
|
||||
}
|
||||
});
|
||||
compassModule.controller('errorHandlingModalController',function($scope,$modalInstance,message){
|
||||
$scope.warning = message.data;
|
||||
$scope.status = message.status;
|
||||
|
||||
$scope.ok =function(){
|
||||
$modalInstance.close();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
@ -25,8 +25,7 @@ define(['uiRouter'], function() {
|
||||
"remember": Boolean($scope.remember)
|
||||
};
|
||||
authService.login(credentials).success(function(data) {
|
||||
rememberMe.setCookies("isAuthenticated","true",0.0833,Boolean($scope.remember));
|
||||
//authService.isAuthenticated = true;
|
||||
authService.setLogin($scope.remember);
|
||||
$state.transitionTo("clusterList");
|
||||
}).error(function(response) {
|
||||
console.log(response);
|
||||
|
@ -1,5 +1,5 @@
|
||||
define(['angular'], function() {
|
||||
var servicesModule = angular.module('compass.services', []);
|
||||
define(['angular','uiBootstrap'], function(ng, uiBootstrap) {
|
||||
var servicesModule = angular.module('compass.services', ['ui.bootstrap']);
|
||||
// stateService is used for dynamically add/edit state
|
||||
/* .service('stateService', ['$state',
|
||||
function($state) {
|
||||
@ -503,12 +503,17 @@ define(['angular'], function() {
|
||||
}
|
||||
]);
|
||||
|
||||
servicesModule.service('authService', ['$http', 'dataService',
|
||||
function($http, dataService) {
|
||||
this.isAuthenticated = true;
|
||||
servicesModule.service('authService', ['$http', 'dataService','rememberMe',
|
||||
function($http, dataService,rememberMe) {
|
||||
this.isAuthenticated = false;
|
||||
|
||||
this.setLogin = function(isLogin) {
|
||||
this.isAuthenticated = isLogin;
|
||||
this.setLogin = function(remember) {
|
||||
this.isAuthenticated = true;
|
||||
rememberMe.setCookies("isAuthenticated","true",0.0833,Boolean(remember));
|
||||
};
|
||||
this.setLogout = function(){
|
||||
this.isAuthenticated = false;
|
||||
rememberMe.setCookies("isAuthenticated", "false", -30);
|
||||
}
|
||||
|
||||
this.login = function(user) {
|
||||
@ -516,13 +521,25 @@ define(['angular'], function() {
|
||||
};
|
||||
|
||||
this.logout = function() {
|
||||
//this.isAuthenticated = false;
|
||||
return dataService.logout();
|
||||
};
|
||||
}
|
||||
]);
|
||||
servicesModule.factory('authenticationInterceptor', ['$q', '$location',
|
||||
function($q, $location) {
|
||||
servicesModule.service('modalService',function($modal){
|
||||
this.show = function(message){
|
||||
return $modal.open({
|
||||
templateUrl: 'messagemodal.html',
|
||||
controller: 'errorHandlingModalController',
|
||||
resolve:{
|
||||
message: function(){
|
||||
return message;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
servicesModule.factory('authenticationInterceptor', ['$q', '$location','$injector',
|
||||
function($q, $location, $injector) {
|
||||
return {
|
||||
response: function(response) {
|
||||
return response;
|
||||
@ -532,6 +549,13 @@ define(['angular'], function() {
|
||||
console.log("Response Error 401", rejection);
|
||||
$location.path('/login');
|
||||
}
|
||||
else{
|
||||
if(rejection.config.url && rejection.config.url != "/api/users/login")
|
||||
{
|
||||
var modal = $injector.get("modalService");
|
||||
modal.show(rejection);
|
||||
}
|
||||
}
|
||||
|
||||
return $q.reject(rejection);
|
||||
}
|
||||
@ -557,8 +581,13 @@ define(['angular'], function() {
|
||||
var ca = document.cookie.split(';');
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) == ' ') c = c.substring(1);
|
||||
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
|
||||
while (c.charAt(0) == ' ')
|
||||
c = c.substring(1);
|
||||
if (c.indexOf(name) != -1)
|
||||
{
|
||||
console.log("inside")
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
|
||||
}
|
||||
return "";
|
||||
|
@ -485,14 +485,15 @@ define(['uiRouter', 'angularTable', 'angularDragDrop', 'angularTouch', 'ngSpinne
|
||||
wizardFactory.setCommitState(commitState);
|
||||
wizardFactory.setAllMachinesHost($scope.allservers);
|
||||
|
||||
}).error(function(response) {
|
||||
var commitState = {
|
||||
"name": "sv_selection",
|
||||
"state": "success",
|
||||
"message": response
|
||||
};
|
||||
wizardFactory.setCommitState(commitState);
|
||||
});
|
||||
// .error(function(response) {
|
||||
// var commitState = {
|
||||
// "name": "sv_selection",
|
||||
// "state": "success",
|
||||
// "message": response
|
||||
// };
|
||||
// wizardFactory.setCommitState(commitState);
|
||||
// });
|
||||
//wizardFactory.setServers(selectedServers);
|
||||
}
|
||||
};
|
||||
@ -601,14 +602,15 @@ define(['uiRouter', 'angularTable', 'angularDragDrop', 'angularTouch', 'ngSpinne
|
||||
"message": ""
|
||||
};
|
||||
wizardFactory.setCommitState(commitState);
|
||||
}).error(function(response) {
|
||||
var commitState = {
|
||||
"name": "os_global",
|
||||
"state": "error",
|
||||
"message": response
|
||||
};
|
||||
wizardFactory.setCommitState(commitState);
|
||||
});
|
||||
// .error(function(response) {
|
||||
// var commitState = {
|
||||
// "name": "os_global",
|
||||
// "state": "error",
|
||||
// "message": response
|
||||
// };
|
||||
// wizardFactory.setCommitState(commitState);
|
||||
// });
|
||||
} else {
|
||||
var message = {};
|
||||
if ($scope.generalForm.$error.required) {
|
||||
@ -1107,14 +1109,15 @@ define(['uiRouter', 'angularTable', 'angularDragDrop', 'angularTouch', 'ngSpinne
|
||||
"message": ""
|
||||
};
|
||||
wizardFactory.setCommitState(commitState);
|
||||
}).error(function(response) {
|
||||
var commitState = {
|
||||
"name": "partition",
|
||||
"state": "error",
|
||||
"message": response
|
||||
};
|
||||
wizardFactory.setCommitState(commitState);
|
||||
});
|
||||
// .error(function(response) {
|
||||
// var commitState = {
|
||||
// "name": "partition",
|
||||
// "state": "error",
|
||||
// "message": response
|
||||
// };
|
||||
// wizardFactory.setCommitState(commitState);
|
||||
// });
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -1259,14 +1262,15 @@ define(['uiRouter', 'angularTable', 'angularDragDrop', 'angularTouch', 'ngSpinne
|
||||
"message": ""
|
||||
};
|
||||
wizardFactory.setCommitState(commitState);
|
||||
}).error(function(response) {
|
||||
var commitState = {
|
||||
"name": "package_config",
|
||||
"state": "error",
|
||||
"message": response
|
||||
};
|
||||
wizardFactory.setCommitState(commitState);
|
||||
});
|
||||
// .error(function(response) {
|
||||
// var commitState = {
|
||||
// "name": "package_config",
|
||||
// "state": "error",
|
||||
// "message": response
|
||||
// };
|
||||
// wizardFactory.setCommitState(commitState);
|
||||
// });
|
||||
};
|
||||
});
|
||||
|
||||
@ -1611,14 +1615,15 @@ define(['uiRouter', 'angularTable', 'angularDragDrop', 'angularTouch', 'ngSpinne
|
||||
"message": ""
|
||||
};
|
||||
wizardFactory.setCommitState(commitState);
|
||||
}).error(function(response) {
|
||||
var commitState = {
|
||||
"name": "network_mapping",
|
||||
"state": "error",
|
||||
"message": response
|
||||
};
|
||||
wizardFactory.setCommitState(commitState);
|
||||
});
|
||||
// .error(function(response) {
|
||||
// var commitState = {
|
||||
// "name": "network_mapping",
|
||||
// "state": "error",
|
||||
// "message": response
|
||||
// };
|
||||
// wizardFactory.setCommitState(commitState);
|
||||
// });
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -53,24 +53,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<script type="text/ng-template" id="messagemodal.html">
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-title">
|
||||
<i class="ace-icon fa fa-exclamation-triangle orange"></i>
|
||||
Warning
|
||||
</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<span ng-if="warning.message">
|
||||
{{warning.message}}
|
||||
</span>
|
||||
<span ng-if="warning.message === undefined">
|
||||
Error occured.
|
||||
</span>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-primary" ng-click="ok()">OK</button>
|
||||
</div>
|
||||
</script>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user