@@ -176,15 +176,32 @@ DataPacks.prototype.runDataPackProcess = function(dataPackData, options, onSucce
176176 self . vlocity . checkLogin ( function ( ) {
177177 self . vlocity . jsForceConnection . apex . post ( self . dataPacksEndpoint , dataPackData , function ( err , result ) {
178178
179- if ( typeof result == "string" ) {
180- result = JSON . parse ( result ) ;
181- }
179+ if ( err ) {
180+ if ( dataPackData . isRetry ) {
181+ console . error ( '\x1b[31m' , 'ERROR >>' , '\x1b[0m' , dataPackId , err ) ;
182+
183+ if ( onError ) onError ( err ) ;
184+ else if ( onSuccess ) onSuccess ( err ) ;
185+ else throw err ;
186+ } else {
187+ console . error ( '\x1b[31m' , 'RETRYING FOR ERROR >>' , '\x1b[0m' , dataPackId , err ) ;
188+
189+ self . vlocity . isLoggedIn = false ;
190+ dataPackData . isRetry = true ;
191+
192+ setTimeout ( function ( ) { self . runDataPackProcess ( dataPackData , options , onSuccess , onError ) ; } , 1000 ) ;
193+ }
194+ } else {
195+ dataPackData . isRetry = false ;
182196
183- if ( self . vlocity . verbose ) {
184- console . log ( 'Result' , result ) ;
185- }
197+ if ( typeof result == "string" ) {
198+ result = JSON . parse ( result ) ;
199+ }
200+
201+ if ( self . vlocity . verbose ) {
202+ console . log ( 'Result' , result ) ;
203+ }
186204
187- if ( result ) {
188205 if ( result . Total > 0 ) {
189206 if ( dataPackData . processType == "Export"
190207 && dataPackData . processData
@@ -205,29 +222,26 @@ DataPacks.prototype.runDataPackProcess = function(dataPackData, options, onSucce
205222 console . log ( '\x1b[32m' , 'Activated >>' , '\x1b[0m' , activatedEntity . VlocityDataPackKey ) ;
206223 } ) ;
207224 }
208- }
209-
210- if ( err ) {
211- console . error ( '\x1b[31m' , 'ERROR >>' , '\x1b[0m' , dataPackId , err ) ;
212-
213- // Need to hook this in an interesting way
214- var packError = { VlocityDataPackId : dataPackId , AllErrorMessage : err } ;
215-
216- if ( onError ) onError ( err ) ;
217- else if ( onSuccess ) onSuccess ( err ) ;
218- else throw err ;
219- } else if ( / ( R e a d y | I n P r o g r e s s ) / . test ( result . Status ) ) {
220- dataPackData . processData = result ;
221-
222- setTimeout ( function ( ) { self . runDataPackProcess ( dataPackData , options , onSuccess , onError ) ; } , result . Async ? 3000 : 1 ) ;
223- } else if ( / ( C o m p l e t e | D e l e t e d ) / . test ( result . Status ) ) {
224-
225- if ( onSuccess ) onSuccess ( result ) ;
226- else console . log ( result ) ;
227- } else if ( / E r r o r / . test ( result . Status ) ) {
228- if ( onError ) onError ( result ) ;
229- else if ( onSuccess ) onSuccess ( result ) ;
230- else console . log ( result ) ;
225+
226+ if ( result . activationError ) {
227+ result . activationError . forEach ( function ( activatedEntity ) {
228+ console . log ( '\x1b[31m' , 'Activation Error >>' , '\x1b[0m' , activatedEntity . VlocityDataPackKey , '---' , activatedEntity . ActivationMessage ) ;
229+ } ) ;
230+ }
231+
232+ if ( / ( R e a d y | I n P r o g r e s s ) / . test ( result . Status ) ) {
233+ dataPackData . processData = result ;
234+
235+ setTimeout ( function ( ) { self . runDataPackProcess ( dataPackData , options , onSuccess , onError ) ; } , result . Async ? 3000 : 1 ) ;
236+ } else if ( / ( C o m p l e t e | D e l e t e d ) / . test ( result . Status ) ) {
237+
238+ if ( onSuccess ) onSuccess ( result ) ;
239+ else console . log ( result ) ;
240+ } else if ( / E r r o r / . test ( result . Status ) ) {
241+ if ( onError ) onError ( result ) ;
242+ else if ( onSuccess ) onSuccess ( result ) ;
243+ else console . log ( result ) ;
244+ }
231245 }
232246 } ) ;
233247 } ) ;
0 commit comments