diff --git a/src/state/stateService.ts b/src/state/stateService.ts index fbe35e5a1..ae59a1bfd 100644 --- a/src/state/stateService.ts +++ b/src/state/stateService.ts @@ -487,7 +487,7 @@ export class StateService { console.error($error$); console.error($error$.stack); } else if ($error$ instanceof Rejection) { - console.error($error$); + console.error($error$.toString()); if ($error$.detail && $error$.detail.stack) console.error($error$.detail.stack); } else { diff --git a/src/transition/rejectFactory.ts b/src/transition/rejectFactory.ts index ca073844d..ca5bb8a32 100644 --- a/src/transition/rejectFactory.ts +++ b/src/transition/rejectFactory.ts @@ -37,7 +37,7 @@ export class Rejection { /** Returns a TransitionRejection due to transition superseded */ static superseded(detail?: any, options?: any) { - let message = "The transition has been superseded by a different transition (see detail)."; + let message = "The transition has been superseded by a different transition"; let rejection = new Rejection(RejectType.SUPERSEDED, message, detail); if (options && options.redirected) { rejection.redirected = true; @@ -52,27 +52,27 @@ export class Rejection { /** Returns a TransitionRejection due to invalid transition */ static invalid(detail?: any) { - let message = "This transition is invalid (see detail)"; + let message = "This transition is invalid"; return new Rejection(RejectType.INVALID, message, detail); } /** Returns a TransitionRejection due to ignored transition */ static ignored(detail?: any) { - let message = "The transition was ignored."; + let message = "The transition was ignored"; return new Rejection(RejectType.IGNORED, message, detail); } /** Returns a TransitionRejection due to aborted transition */ static aborted(detail?: any) { // TODO think about how to encapsulate an Error() object - let message = "The transition has been aborted."; + let message = "The transition has been aborted"; return new Rejection(RejectType.ABORTED, message, detail); } /** Returns a TransitionRejection due to aborted transition */ static errored(detail?: any) { // TODO think about how to encapsulate an Error() object - let message = "The transition errored."; + let message = "The transition errored"; return new Rejection(RejectType.ERROR, message, detail); } } diff --git a/src/transition/transitionHook.ts b/src/transition/transitionHook.ts index 4833ce246..44f86b9ee 100644 --- a/src/transition/transitionHook.ts +++ b/src/transition/transitionHook.ts @@ -89,14 +89,16 @@ export class TransitionHook { static runSynchronousHooks(hooks: TransitionHook[], swallowExceptions: boolean = false): Promise { let results: Promise[] = []; for (let i = 0; i < hooks.length; i++) { + let hook = hooks[i]; try { - results.push(hooks[i].invokeHook()); + results.push(hook.invokeHook()); } catch (exception) { if (!swallowExceptions) { return Rejection.errored(exception).toPromise(); } - console.error("Swallowed exception during synchronous hook handler: " + exception); // TODO: What to do here? + let errorHandler = hook.transition.router.stateService.defaultErrorHandler(); + errorHandler(exception); } } diff --git a/test/ng1/stateEventsSpec.js b/test/ng1/stateEventsSpec.js index 49e7584fa..b824644f8 100644 --- a/test/ng1/stateEventsSpec.js +++ b/test/ng1/stateEventsSpec.js @@ -272,6 +272,7 @@ describe('UI-Router v0.2.x $state events', function () { it('aborts pending transitions even when going back to the current state', inject(function ($state, $q) { initStateTo(A); logEvents = true; + $state.defaultErrorHandler(function() {}); var superseded = $state.transitionTo(B, {}); $state.transitionTo(A, {}); @@ -284,6 +285,7 @@ describe('UI-Router v0.2.x $state events', function () { it('aborts pending transitions (last call wins)', inject(function ($state, $q) { initStateTo(A); logEvents = true; + $state.defaultErrorHandler(function() {}); var superseded = $state.transitionTo(B, {}); $state.transitionTo(C, {}); diff --git a/test/ng1/stateSpec.js b/test/ng1/stateSpec.js index e0e91abb3..2a2faa965 100644 --- a/test/ng1/stateSpec.js +++ b/test/ng1/stateSpec.js @@ -1909,6 +1909,7 @@ describe('otherwise and state redirects', function() { })); it("should not go into an infinite loop", inject(function($location, $rootScope, $state, $urlRouter, $httpBackend) { + $state.defaultErrorHandler(function() {}); $httpBackend.expectGET("login.html").respond("login page"); $location.url("notmatched"); $urlRouter.update(true); @@ -1987,7 +1988,6 @@ describe('transition hook', function() { $transitions.onStart({ to: 'home' }, function($transition$) { if (!$transition$.options().reload && count++ < 5) { - console.log("forcing re-enter (reload) of home state "); var options = $transition$.options(); return $state.target($transition$.to(), $transition$.params("to"), extend({}, options, {reload: true})); } diff --git a/test/ng1/transitionSpec.ts b/test/ng1/transitionSpec.ts index 52c637ebd..a1f075340 100644 --- a/test/ng1/transitionSpec.ts +++ b/test/ng1/transitionSpec.ts @@ -283,6 +283,10 @@ describe('transition', function () { }); describe('.onSuccess()', function() { + beforeEach(inject($uiRouter => { + $uiRouter.stateService.defaultErrorHandler(function() {}) + })); + it('should only be called if the transition succeeds', inject(function($transitions, $q) { transitionProvider.onSuccess({ from: "*", to: "*" }, function(trans) { states.push(trans.to().name); }); transitionProvider.onEnter({ from: "A", entering: "C" }, function() { return false; }); diff --git a/test/ng1/viewHookSpec.ts b/test/ng1/viewHookSpec.ts index 1742448d9..67b60c373 100644 --- a/test/ng1/viewHookSpec.ts +++ b/test/ng1/viewHookSpec.ts @@ -101,10 +101,11 @@ describe("view hooks", () => { expect($state.current.name).toBe('baz'); }); - it("can cancel the transition by returning a rejected promise", inject(($q) => { + it("can cancel the transition by returning a rejected promise", inject(($q, $state) => { ctrl.prototype.uiCanExit = function() { log += "canexit;"; return $q.reject('nope'); }; initial(); + $state.defaultErrorHandler(function() {}); $state.go('bar'); $q.flush(); $timeout.flush(); expect(log).toBe('canexit;'); expect($state.current.name).toBe('foo');