angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.54k stars 3k forks source link

Expose `defaultErrorHandler` from `$state` on `$stateProvider` #3559

Closed adamreisnz closed 6 years ago

adamreisnz commented 6 years ago

This is a:

My version of UI-Router is: 1.0.10

Feature Request

Make the [defaultErrorHandler](https://ui-router.github.io/ng1/docs/latest/classes/state.stateservice.html#defaulterrorhandler) method from StateService accessible in the configuration phase of Angular, so that we can apply custom error handling (like capturing errors with Sentry) in one place.

Currently, I need to to it in the config phase for Angular exceptions (using a decorator for $exceptionHandler) and then in the run phase for UI-Router, because the defaultErrorHandler method is only available on the $state injectable it seems, and not on any injectables available during the config phase.

It'd be great if the defaultErrorHandler method could be exposed on for example the $stateProvider in addition, allowing us to call it from the config phase.

christopherthielen commented 6 years ago

The $stateProvider facade is mostly still there for backwards compatiblity. You can inject the $uiRouterProvider (or $uiRouter at runtime) and access all the services through that reference.

.config($uiRouterProvider => 
  $uiRouterProvider.stateService.defaultErrorHandler(...)
);
adamreisnz commented 6 years ago

Alright, will use that, thanks