On a project I'm working on, I'm working on implementing a developer notification system at my project lead's behest. The way it works, is that if a front-end error occurs, the development team gets sent an error e-mail.
However, with my current implementation, it seems I have the following circular dependency:
$rootScope <- $http <- $exceptionHandler <- $rootScope
In the following code:
(function() {
'use strict';
// Using .config to 'decorate' the exception handler.
angular.module('app').config(function($provide) {
$provide.decorator('$exceptionHandler', ['$delegate', '$http', dispatchErrorEmail]);
});
function dispatchErrorEmail($delegate, $http) {
return function (exception, cause) {
// Execute default implementation.
$delegate(exception, cause);
// Angular exceptions fail softly, but generate an error email.
var args = {
'exception': exception,
'cause': cause
};
$http.post('/api/admin/ErrorNotification', args);
};
}
})();
As you can see, there's one small problem: I'm not actually using $rootScope in any way whatsoever in my decoration of $errorHandler.
What's more, neither the $provide.decorator or the $errorHandler documentation makes any note of $rootScope being implicitly included.
Questions:
- How is
$rootScopegetting injected into this service, exactly? - In what way can I rewrite my
$exceptionHandlerdecoration to avoid this circular dependency?