11import {
22 BadRequestException ,
3+ HttpException ,
34 HttpStatus ,
45 Injectable ,
56 RequestTimeoutException ,
@@ -55,7 +56,7 @@ export class BackendsService extends AbstractQueueProcessor {
5556 { new : true } ,
5657 ) ;
5758 if ( isSyncedJob ) {
58- await this . identitiesService . model . findByIdAndUpdate ( isSyncedJob . concernedTo . id , {
59+ await this . identitiesService . model . findByIdAndUpdate ( isSyncedJob ? .concernedTo ? .id , {
5960 $set : {
6061 state : IdentityState . SYNCED ,
6162 } ,
@@ -96,7 +97,7 @@ export class BackendsService extends AbstractQueueProcessor {
9697 } ,
9798 { new : true } ,
9899 ) ;
99- await this . identitiesService . model . findByIdAndUpdate ( failedJob . concernedTo . id , {
100+ await this . identitiesService . model . findByIdAndUpdate ( failedJob ? .concernedTo ? .id , {
100101 $set : {
101102 state : IdentityState . ON_ERROR ,
102103 } ,
@@ -115,8 +116,8 @@ export class BackendsService extends AbstractQueueProcessor {
115116 } ,
116117 { upsert : true , new : true } ,
117118 ) ;
118- // console.log('completedJob', completedJob);
119- await this . identitiesService . model . findByIdAndUpdate ( completedJob . concernedTo . id , {
119+ console . log ( 'completedJob' , completedJob ) ;
120+ await this . identitiesService . model . findByIdAndUpdate ( completedJob ? .concernedTo ? .id , {
120121 $set : {
121122 state : IdentityState . SYNCED ,
122123 } ,
@@ -142,17 +143,26 @@ export class BackendsService extends AbstractQueueProcessor {
142143
143144 const result = { } ;
144145 for ( const identity of identities ) {
145- const [ executedJob ] = await this . executeJob (
146- identity . action ,
147- identity . identity . _id ,
148- { identity } ,
149- {
150- ...options ,
151- task : task . _id ,
152- } ,
153- ) ;
154- result [ identity . identity . _id ] = executedJob ;
146+ try {
147+ this . logger . debug ( `Syncing identity ${ identity . identity . _id } ` ) ;
148+ const [ executedJob ] = await this . executeJob (
149+ identity . action ,
150+ identity . identity . _id ,
151+ { identity } ,
152+ {
153+ ...options ,
154+ task : task . _id ,
155+ } ,
156+ ) ;
157+ result [ identity . identity . _id ] = executedJob ;
158+ } catch ( err : HttpException ) {
159+ this . logger . error ( `Error while syncing identity ${ identity . identity . _id } ` , err ) ;
160+ result [ identity . identity . _id ] = {
161+ ...err . response ,
162+ } ;
163+ }
155164 }
165+
156166 return result ;
157167 }
158168
0 commit comments