@@ -5,16 +5,22 @@ const connections = [];
55
66function ProcessLauncher ( publicAPI , model ) {
77 publicAPI . start = ( config ) => {
8- var xhr = new XMLHttpRequest ( ) ,
9- url = model . endPoint ;
8+ const xhr = new XMLHttpRequest ( ) ;
9+ const url = model . endPoint ;
10+ if ( ! model . _retry ) {
11+ model . _retry = config . launcherRetry || [ ] ;
12+ }
1013
1114 xhr . open ( 'POST' , url , true ) ;
1215
1316 if ( config . headers ) {
14- Object . entries ( config . headers ) . forEach ( ( [ key , value ] ) =>
17+ model . _headers = config . headers ;
18+ delete config . headers ;
19+ }
20+ if ( model . _headers ) {
21+ Object . entries ( model . _headers ) . forEach ( ( [ key , value ] ) =>
1522 xhr . setRequestHeader ( key , value )
1623 ) ;
17- delete config . headers ;
1824 }
1925
2026 xhr . responseType = 'json' ;
@@ -27,8 +33,12 @@ function ProcessLauncher(publicAPI, model) {
2733 connections . push ( response ) ;
2834 publicAPI . fireProcessReady ( response ) ;
2935 return ;
36+ } else if ( xhr . status === 503 && model . _retry . length > 0 ) {
37+ const timeout = model . _retry . shift ( ) ;
38+ setTimeout ( publicAPI . start , timeout , config ) ;
39+ } else {
40+ publicAPI . fireError ( xhr ) ;
3041 }
31- publicAPI . fireError ( xhr ) ;
3242 } ;
3343
3444 xhr . onerror = ( e ) => {
0 commit comments