Skip to content

Commit 5214a55

Browse files
In Angular2Spa, server-side rendering now reports all errors
1 parent 2ba5a0a commit 5214a55

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

templates/Angular2Spa/ClientApp/boot-server.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,27 @@ enableProdMode();
88
const platform = platformNodeDynamic();
99

1010
export default function (params: any) : Promise<{ html: string, globals?: any }> {
11-
const requestZone = Zone.current.fork({
12-
name: 'angular-universal request',
13-
properties: {
14-
baseUrl: '/',
15-
requestUrl: params.url,
16-
originUrl: params.origin,
17-
preboot: false,
18-
// TODO: Render just the <app> component instead of wrapping it inside an extra HTML document
19-
// Waiting on https://github.com/angular/universal/issues/347
20-
document: '<!DOCTYPE html><html><head></head><body><app></app></body></html>'
21-
}
22-
});
23-
24-
return requestZone.run<Promise<string>>(() => platform.serializeModule(AppModule))
25-
.then(html => {
26-
return { html: html };
11+
return new Promise((resolve, reject) => {
12+
const requestZone = Zone.current.fork({
13+
name: 'angular-universal request',
14+
properties: {
15+
baseUrl: '/',
16+
requestUrl: params.url,
17+
originUrl: params.origin,
18+
preboot: false,
19+
// TODO: Render just the <app> component instead of wrapping it inside an extra HTML document
20+
// Waiting on https://github.com/angular/universal/issues/347
21+
document: '<!DOCTYPE html><html><head></head><body><app></app></body></html>'
22+
},
23+
onHandleError: (parentZone, currentZone, targetZone, error) => {
24+
// If any error occurs while rendering the module, reject the whole operation
25+
reject(error);
26+
return true;
27+
}
2728
});
29+
30+
return requestZone.run<Promise<string>>(() => platform.serializeModule(AppModule)).then(html => {
31+
resolve({ html: html });
32+
}, reject);
33+
});
2834
}

0 commit comments

Comments
 (0)