I'm writing an error-logging module to add Raygun logging to an AngularJS application. The standard method is to register a decorator for $exceptionHandler
like so:
$provide.decorator("$exceptionHandler", ['$delegate', function($delegate) {
return function (exception, cause) {
Raygun.send(exception);
$delegate(exception, cause);
}
}])
However, this has an order dependence in that the decorator must be installed before the DI framework first loads $exceptionHandler
. If I'm wrapping this code in a module, the order dependence is even less obvious, and it's easy for the client to initialize things in the wrong order and have no idea why Raygun.send
isn't getting called. (I was that client for a day and a half. In my defense, this is my first experience with Angular.)
I'd like to persuade Angular's DI framework to load my error-logging module before $exceptionHandler
, with the obvious caveat that I'm hosed if any exceptions are thrown really early in bootstrapping. I thought of trying to register my module as a dependency of $exceptionHandler
, but haven't been able to figure out how to do that yet -- also, it's not actually true that $exceptionHandler
depends upon my code. Is there an idiomatic way to do this that I'm missing?