File tree Expand file tree Collapse file tree 3 files changed +23
-17
lines changed Expand file tree Collapse file tree 3 files changed +23
-17
lines changed Original file line number Diff line number Diff line change @@ -313,10 +313,11 @@ export class IdempotencyHandler<Func extends AnyFunction> {
313
313
) ;
314
314
} catch ( e ) {
315
315
if ( e instanceof IdempotencyItemAlreadyExistsError ) {
316
- const idempotencyRecord : IdempotencyRecord =
317
- await this . #persistenceStore. getRecord (
318
- this . #functionPayloadToBeHashed
319
- ) ;
316
+ const idempotencyRecord : IdempotencyRecord = e . existingRecord ;
317
+ // const idempotencyRecord: IdempotencyRecord =
318
+ // await this.#persistenceStore.getRecord(
319
+ // this.#functionPayloadToBeHashed
320
+ // );
320
321
321
322
return IdempotencyHandler . determineResultFromIdempotencyRecord (
322
323
idempotencyRecord
Original file line number Diff line number Diff line change 1
- import { AttributeValue } from '@aws-sdk/client-dynamodb' ;
2
- //import { IdempotencyRecord } from './persistence';
1
+ import { IdempotencyRecord } from './persistence' ;
3
2
/**
4
3
* Item attempting to be inserted into persistence store already exists and is not expired
5
4
*/
6
5
class IdempotencyItemAlreadyExistsError extends Error {
7
- public existingRecord : Record < string , AttributeValue > | undefined ;
6
+ public existingRecord : IdempotencyRecord ;
8
7
9
- public constructor (
10
- message : string ,
11
- existingRecord : Record < string , AttributeValue > | undefined
12
- ) {
8
+ public constructor ( message : string , existingRecord : IdempotencyRecord ) {
13
9
super ( message ) ;
14
10
this . existingRecord = existingRecord ;
15
11
}
Original file line number Diff line number Diff line change @@ -204,13 +204,22 @@ class DynamoDBPersistenceLayer extends BasePersistenceLayer {
204
204
) ;
205
205
} catch ( error ) {
206
206
if ( error instanceof DynamoDBServiceException ) {
207
- if ( error . name === 'ConditionalCheckFailedException' ) {
208
- if ( error instanceof ConditionalCheckFailedException ) {
209
- throw new IdempotencyItemAlreadyExistsError (
210
- `Failed to put record for already existing idempotency key: ${ record . idempotencyKey } ` ,
211
- error . Item
212
- ) ;
207
+ if ( error instanceof ConditionalCheckFailedException ) {
208
+ if ( ! error . Item ) {
209
+ throw new Error ( 'Item is undefined' ) ;
213
210
}
211
+ const Item = unmarshall ( error . Item ) ;
212
+ throw new IdempotencyItemAlreadyExistsError (
213
+ `Failed to put record for already existing idempotency key: ${ record . idempotencyKey } ` ,
214
+ new IdempotencyRecord ( {
215
+ idempotencyKey : Item [ this . keyAttr ] ,
216
+ status : Item [ this . statusAttr ] ,
217
+ expiryTimestamp : Item [ this . expiryAttr ] ,
218
+ inProgressExpiryTimestamp : Item [ this . inProgressExpiryAttr ] ,
219
+ responseData : Item [ this . dataAttr ] ,
220
+ payloadHash : Item [ this . validationKeyAttr ] ,
221
+ } )
222
+ ) ;
214
223
}
215
224
}
216
225
}
You can’t perform that action at this time.
0 commit comments