This repository was archived by the owner on Jul 26, 2022. It is now read-only.
File tree 2 files changed +49
-9
lines changed
2 files changed +49
-9
lines changed Original file line number Diff line number Diff line change @@ -159,17 +159,25 @@ class Poller {
159
159
}
160
160
161
161
async _updateStatus ( status ) {
162
- this . _logger . debug ( `updating status for ${ this . _namespace } /${ this . _name } to: ${ status } ` )
163
- await this . _status . put ( {
164
- body : {
165
- ...this . _externalSecret ,
166
- status : {
167
- lastSync : `${ new Date ( ) . toISOString ( ) } ` ,
168
- observedGeneration : this . _externalSecret . metadata . generation ,
169
- status
162
+ try {
163
+ this . _logger . debug ( `updating status for ${ this . _namespace } /${ this . _name } to: ${ status } ` )
164
+ await this . _status . put ( {
165
+ body : {
166
+ ...this . _externalSecret ,
167
+ status : {
168
+ lastSync : `${ new Date ( ) . toISOString ( ) } ` ,
169
+ observedGeneration : this . _externalSecret . metadata . generation ,
170
+ status
171
+ }
170
172
}
173
+ } )
174
+ } catch ( err ) {
175
+ if ( err . statusCode !== 409 ) {
176
+ this . _logger . error ( err , `failure while updating status for externalsecret ${ this . _namespace } /${ this . _name } ` )
177
+ throw err
171
178
}
172
- } )
179
+ this . _logger . info ( `status update failed for externalsecret ${ this . _namespace } /${ this . _name } , due to modification, new poller should start` )
180
+ }
173
181
}
174
182
175
183
/**
Original file line number Diff line number Diff line change @@ -371,6 +371,38 @@ describe('Poller', () => {
371
371
} )
372
372
} )
373
373
374
+ describe ( '_updateStatus' , ( ) => {
375
+ it ( 'handles 409 - Conflict' , async ( ) => {
376
+ const conflictError = new Error ( 'Conflict' )
377
+ conflictError . statusCode = 409
378
+ externalSecretsApiMock . status . put . throws ( conflictError )
379
+
380
+ const poller = pollerFactory ( )
381
+
382
+ await poller . _updateStatus ( 'SUCCESS' )
383
+
384
+ expect ( loggerMock . info . calledWith ( `status update failed for externalsecret ${ poller . _namespace } /${ poller . _name } , due to modification, new poller should start` ) ) . to . equal ( true )
385
+ } )
386
+
387
+ it ( 'rethrows other errors' , async ( ) => {
388
+ const notFoundError = new Error ( 'Not Found' )
389
+ notFoundError . statusCode = 404
390
+ externalSecretsApiMock . status . put . throws ( notFoundError )
391
+
392
+ const poller = pollerFactory ( )
393
+ let error
394
+
395
+ try {
396
+ await poller . _updateStatus ( 'SUCCESS' )
397
+ } catch ( err ) {
398
+ error = err
399
+ }
400
+
401
+ expect ( error ) . to . not . equal ( undefined )
402
+ expect ( error . message ) . equals ( 'Not Found' )
403
+ } )
404
+ } )
405
+
374
406
describe ( '_scheduleNextPoll' , ( ) => {
375
407
let poller
376
408
let clock
You can’t perform that action at this time.
0 commit comments