Skip to content

Commit f5fdbbc

Browse files
authored
Ui router error listening (#82)
* Adding listener for errors thrown by ui-router * provide toState name in error message
1 parent 05f2811 commit f5fdbbc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

generated/browser/js/app.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ app.config(function ($urlRouterProvider, $locationProvider) {
1212
});
1313
});
1414

15+
// This app.run is for listening to errors broadcasted by ui-router, usually originating from resolves
16+
app.run(function ($rootScope) {
17+
$rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, thrownError) {
18+
console.info(`The following error was thrown by ui-router while transitioning to state "${toState.name}". The origin of this error is probably a resolve function:`);
19+
console.error(thrownError);
20+
});
21+
});
22+
1523
// This app.run is for controlling access to specific states.
1624
app.run(function ($rootScope, AuthService, $state) {
1725

0 commit comments

Comments
 (0)