Skip to content

Commit 4b6d56f

Browse files
fix(Transition): Reject Transition promise when onBefore error
closes #2561
1 parent 0c123c3 commit 4b6d56f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/transition/transitionHook.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class TransitionHook {
9393
try {
9494
results.push(hooks[i].invokeStep(locals));
9595
} catch (exception) {
96-
if (!swallowExceptions) throw exception;
96+
if (!swallowExceptions) return REJECT.aborted(exception);
9797
console.log("Swallowed exception during synchronous hook handler: " + exception); // TODO: What to do here?
9898
}
9999
}

test/transitionSpec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,23 @@ describe('transition', function () {
123123
expect(result.get().reject.message).toEqual("transition failed");
124124
}));
125125

126+
it('$transition$.promise should reject on error in synchronous hooks', inject(function($transitions, $q) {
127+
var result = new PromiseResult();
128+
129+
transitionProvider.onBefore({ from: "*", to: "third" }, function($transition$) {
130+
result.setPromise($transition$.promise);
131+
throw new Error("transition failed");
132+
});
133+
134+
try {
135+
makeTransition("", "third").run();
136+
} catch (e) {}
137+
$q.flush();
138+
139+
expect(result.called()).toEqual({ resolve: false, reject: true, complete: true });
140+
expect(result.get().reject.detail.message).toEqual("transition failed");
141+
}));
142+
126143
it('should inject $transition$', inject(function($transitions, $q) {
127144
var t = null;
128145

0 commit comments

Comments
 (0)