X Tutup
Skip to content

Commit 5782f06

Browse files
committed
fix(router): rethrow exceptions
Closes #2391
1 parent 4ae7df2 commit 5782f06

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

modules/angular2/src/router/router.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ export class Router {
128128
ObservableWrapper.callNext(this._subject, matchedInstruction.accumulatedUrl);
129129
});
130130

131-
PromiseWrapper.catchError(result, (_) => this._finishNavigating());
131+
PromiseWrapper.catchError(result, (err) => {
132+
this._finishNavigating();
133+
return err;
134+
});
132135

133136
return result;
134137
});

modules/angular2/test/router/router_integration_spec.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {routerInjectables, Router} from 'angular2/router';
2121
import {RouterOutlet} from 'angular2/src/router/router_outlet';
2222
import {SpyLocation} from 'angular2/src/mock/location_mock';
2323
import {Location} from 'angular2/src/router/location';
24+
import {PromiseWrapper} from 'angular2/src/facade/async';
25+
import {BaseException} from 'angular2/src/facade/lang';
2426

2527
export function main() {
2628
describe('router injectables', () => {
@@ -47,6 +49,19 @@ export function main() {
4749
});
4850
}));
4951

52+
it('should rethrow exceptions from component constructors',
53+
inject([AsyncTestCompleter], (async) => {
54+
bootstrap(BrokenAppCmp, testBindings)
55+
.then((applicationRef) => {
56+
var router = applicationRef.hostComponent.router;
57+
PromiseWrapper.catchError(router.navigate('/cause-error'), (error) => {
58+
expect(el).toHaveText('outer { oh no }');
59+
expect(error.message).toBe('oops!');
60+
async.done();
61+
});
62+
});
63+
}));
64+
5065
// TODO: add a test in which the child component has bindings
5166
});
5267
}
@@ -57,11 +72,24 @@ export function main() {
5772
class HelloCmp {
5873
}
5974

60-
6175
@Component({selector: 'app-cmp'})
6276
@View({template: "outer { <router-outlet></router-outlet> }", directives: [RouterOutlet]})
6377
@RouteConfig([{path: '/', component: HelloCmp}])
6478
class AppCmp {
6579
router: Router;
6680
constructor(router: Router) { this.router = router; }
6781
}
82+
83+
@Component({selector: 'oops-cmp'})
84+
@View({template: "oh no"})
85+
class BrokenCmp {
86+
constructor() { throw new BaseException('oops!'); }
87+
}
88+
89+
@Component({selector: 'app-cmp'})
90+
@View({template: "outer { <router-outlet></router-outlet> }", directives: [RouterOutlet]})
91+
@RouteConfig([{path: '/cause-error', component: BrokenCmp}])
92+
class BrokenAppCmp {
93+
router: Router;
94+
constructor(router: Router) { this.router = router; }
95+
}

0 commit comments

Comments
 (0)
X Tutup