Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Prevent circular redirects on certain pages // Issue #16
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrokyrychuk committed Sep 19, 2015
1 parent 94e81f9 commit 966a219
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion app/scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
.module('siteApp')
.controller('MainController', MainController);

function MainController($scope, $location) {
function MainController($scope, $location, $log, $state, notifyUser) {
var vm = this;

vm.isRouteActive = isRouteActive;
Expand All @@ -31,6 +31,12 @@
return $location.path();
}, onPathChange);

// Prevent circular redirects on certain pages and notify user that SA is
// not being run.
// $stateChangeError occurs when there are errors in resolve functions,
// which usually means that backend is unreachable.
$scope.$on('$stateChangeError', onStateChangeError);

////////////

function isRouteActive(route) {
Expand All @@ -44,6 +50,18 @@
path = path.substring(1);
vm.currentPage = path.substring(0, 1).toUpperCase() + path.substring(1);
}

function onStateChangeError(event, toState, toParams, fromState, fromParams,
error) {
event.preventDefault();

$log.error('Unable to perform transition from ', fromState, ' to ',
toState, '. Error: ', error);
notifyUser('error', 'Unexpected error occured. Please, make sure that ' +
'SmartAnthill is running.');

$state.go('dashboard');
}
}

})();

0 comments on commit 966a219

Please sign in to comment.