@@ -8,21 +8,27 @@ enableProdMode();
8
8
const platform = platformNodeDynamic ( ) ;
9
9
10
10
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
+ }
27
28
} ) ;
29
+
30
+ return requestZone . run < Promise < string > > ( ( ) => platform . serializeModule ( AppModule ) ) . then ( html => {
31
+ resolve ( { html : html } ) ;
32
+ } , reject ) ;
33
+ } ) ;
28
34
}
0 commit comments