In Angular2Spa, server-side rendering now reports all errors

This commit is contained in:
SteveSandersonMS
2016-09-21 09:29:13 +01:00
parent 2ba5a0ac93
commit 5214a553a7

View File

@@ -8,6 +8,7 @@ enableProdMode();
const platform = platformNodeDynamic(); const platform = platformNodeDynamic();
export default function (params: any) : Promise<{ html: string, globals?: any }> { export default function (params: any) : Promise<{ html: string, globals?: any }> {
return new Promise((resolve, reject) => {
const requestZone = Zone.current.fork({ const requestZone = Zone.current.fork({
name: 'angular-universal request', name: 'angular-universal request',
properties: { properties: {
@@ -18,11 +19,16 @@ export default function (params: any) : Promise<{ html: string, globals?: any }>
// TODO: Render just the <app> component instead of wrapping it inside an extra HTML document // TODO: Render just the <app> component instead of wrapping it inside an extra HTML document
// Waiting on https://github.com/angular/universal/issues/347 // Waiting on https://github.com/angular/universal/issues/347
document: '<!DOCTYPE html><html><head></head><body><app></app></body></html>' document: '<!DOCTYPE html><html><head></head><body><app></app></body></html>'
},
onHandleError: (parentZone, currentZone, targetZone, error) => {
// If any error occurs while rendering the module, reject the whole operation
reject(error);
return true;
} }
}); });
return requestZone.run<Promise<string>>(() => platform.serializeModule(AppModule)) return requestZone.run<Promise<string>>(() => platform.serializeModule(AppModule)).then(html => {
.then(html => { resolve({ html: html });
return { html: html }; }, reject);
}); });
} }