How to catch Angular ui-router resolve errors

It’s more than annoying to have just a blank page and no errors in console when your issue is inside ui-router resolve. Finally I found a pretty nice solution, don’t know why it’s not provided “from the box”. In case of error ui-router sends specific event $stateChangeError that we could listen for:

$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error){

and now wow! we have an exact error in console and no need to guess what’s wrong with your code anymore.