From f5fdbbc9d3f4bdeea0fee81a402c53532b34c740 Mon Sep 17 00:00:00 2001 From: Joseph Alves Date: Sun, 18 Sep 2016 19:53:01 -0400 Subject: [PATCH] Ui router error listening (#82) * Adding listener for errors thrown by ui-router * provide toState name in error message --- generated/browser/js/app.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/generated/browser/js/app.js b/generated/browser/js/app.js index f8a5c0b..a5de5cb 100644 --- a/generated/browser/js/app.js +++ b/generated/browser/js/app.js @@ -12,6 +12,14 @@ app.config(function ($urlRouterProvider, $locationProvider) { }); }); +// This app.run is for listening to errors broadcasted by ui-router, usually originating from resolves +app.run(function ($rootScope) { + $rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, thrownError) { + 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:`); + console.error(thrownError); + }); +}); + // This app.run is for controlling access to specific states. app.run(function ($rootScope, AuthService, $state) {