From 4b6d56fb88ba7a0145425e2b05d32ea47d986b20 Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Sun, 27 Mar 2016 13:03:17 -0500 Subject: [PATCH] fix(Transition): Reject Transition promise when onBefore error closes #2561 --- src/transition/transitionHook.ts | 2 +- test/transitionSpec.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/transition/transitionHook.ts b/src/transition/transitionHook.ts index 31c69a0fd..4125a5f25 100644 --- a/src/transition/transitionHook.ts +++ b/src/transition/transitionHook.ts @@ -93,7 +93,7 @@ export class TransitionHook { try { results.push(hooks[i].invokeStep(locals)); } catch (exception) { - if (!swallowExceptions) throw exception; + if (!swallowExceptions) return REJECT.aborted(exception); console.log("Swallowed exception during synchronous hook handler: " + exception); // TODO: What to do here? } } diff --git a/test/transitionSpec.ts b/test/transitionSpec.ts index 4adae99ca..33fd847f2 100644 --- a/test/transitionSpec.ts +++ b/test/transitionSpec.ts @@ -123,6 +123,23 @@ describe('transition', function () { expect(result.get().reject.message).toEqual("transition failed"); })); + it('$transition$.promise should reject on error in synchronous hooks', inject(function($transitions, $q) { + var result = new PromiseResult(); + + transitionProvider.onBefore({ from: "*", to: "third" }, function($transition$) { + result.setPromise($transition$.promise); + throw new Error("transition failed"); + }); + + try { + makeTransition("", "third").run(); + } catch (e) {} + $q.flush(); + + expect(result.called()).toEqual({ resolve: false, reject: true, complete: true }); + expect(result.get().reject.detail.message).toEqual("transition failed"); + })); + it('should inject $transition$', inject(function($transitions, $q) { var t = null;