|
1 |
| -angular.module('services.exceptionHandler', ['services.notifications', 'services.localizedMessages'], ['$provide', function($provide) { |
2 |
| - |
3 |
| - $provide.decorator('$exceptionHandler', ['$injector', '$delegate', 'localizedMessages', function ($injector, $delegate, localizedMessages) { |
| 1 | +angular.module('services.exceptionHandler', ['services.notifications', 'services.localizedMessages']); |
4 | 2 |
|
| 3 | +angular.module('services.exceptionHandler').factory('exceptionHandlerFactory', ['$injector', 'localizedMessages', function($injector, localizedMessages) { |
| 4 | + return function($delegate) { |
| 5 | + var notifications; |
5 | 6 | return function (exception, cause) {
|
6 |
| - //need to get the notications service from injector due to circular dependencies: |
| 7 | + // Lazy load notifications to get around circular dependency |
7 | 8 | //Circular dependency: $rootScope <- notifications <- $exceptionHandler
|
| 9 | + var notifications = notifications || $injector.get('notifications'); |
| 10 | + |
| 11 | + // Pass through to original handler |
8 | 12 | $delegate(exception, cause);
|
9 |
| - $injector.get('notifications').pushForCurrentRoute(localizedMessages.get('error.fatal'), 'error', { |
| 13 | + |
| 14 | + // Push a notification error |
| 15 | + notifications.pushForCurrentRoute(localizedMessages.get('error.fatal'), 'error', { |
10 | 16 | exception:exception,
|
11 | 17 | cause:cause
|
12 | 18 | });
|
13 | 19 | };
|
| 20 | + }; |
| 21 | +}]); |
| 22 | + |
| 23 | +angular.module('services.exceptionHandler').config(['$provide', function($provide) { |
| 24 | + $provide.decorator('$exceptionHandler', ['$delegate', 'exceptionHandlerFactory', function ($delegate, exceptionHandlerFactory) { |
| 25 | + return exceptionHandlerFactory($delegate); |
14 | 26 | }]);
|
15 | 27 | }]);
|
0 commit comments