I’m using the @uirouter/angularjs 1.0.22 npm package in my angularjs 1.6.10 project. I just performed the migration from the legacy ui-router package and have now started to route to components.
What I was thinking about trying to do was use the onError transition hook to handle instances of where an API call results in a 403 or 401 status. I could get more granular than using an angularjs interceptor (for instance handle the error differently depending on the route). It would also allow some child directives/components to make API calls that don’t go through the interceptor for error handling.
It seems like any errors in the resolve function, onEnter, onStart, etc. result in a transition error. In testing, I can also see that the component’s controller’s constructor and $onInit get called before a global $transition.onSuccess hook, that I created in my app’s run block, gets invoked. That’s well and good, but if I throw an error from within the constructor or $onInit, it doesn’t result in a transition error. Does anyone know if that’s the intent?
If that’s the case, it basically means that I’d have to move component initialization logic (which includes the API calls that could result in a 401 or 403) into something like the resolve. Long story short, is there a way to use ui-router as a somewhat generic error handler for errors thrown during component initialization?