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,21 +8,27 @@ 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 }> {
const requestZone = Zone.current.fork({ return new Promise((resolve, reject) => {
name: 'angular-universal request', const requestZone = Zone.current.fork({
properties: { name: 'angular-universal request',
baseUrl: '/', properties: {
requestUrl: params.url, baseUrl: '/',
originUrl: params.origin, requestUrl: params.url,
preboot: false, originUrl: params.origin,
// TODO: Render just the <app> component instead of wrapping it inside an extra HTML document preboot: false,
// Waiting on https://github.com/angular/universal/issues/347 // TODO: Render just the <app> component instead of wrapping it inside an extra HTML document
document: '<!DOCTYPE html><html><head></head><body><app></app></body></html>' // Waiting on https://github.com/angular/universal/issues/347
} document: '<!DOCTYPE html><html><head></head><body><app></app></body></html>'
}); },
onHandleError: (parentZone, currentZone, targetZone, error) => {
return requestZone.run<Promise<string>>(() => platform.serializeModule(AppModule)) // If any error occurs while rendering the module, reject the whole operation
.then(html => { reject(error);
return { html: html }; return true;
}
}); });
return requestZone.run<Promise<string>>(() => platform.serializeModule(AppModule)).then(html => {
resolve({ html: html });
}, reject);
});
} }