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 @@ -202,13 +202,22 @@ class DynamoDBPersistenceLayer extends BasePersistenceLayer {
202
202
) ;
203
203
} catch ( error ) {
204
204
if ( error instanceof DynamoDBServiceException ) {
205
- if ( error . name === 'ConditionalCheckFailedException' ) {
206
- if ( error instanceof ConditionalCheckFailedException ) {
207
- throw new IdempotencyItemAlreadyExistsError (
208
- `Failed to put record for already existing idempotency key: ${ record . idempotencyKey } ` ,
209
- error . Item
210
- ) ;
205
+ if ( error instanceof ConditionalCheckFailedException ) {
206
+ if ( ! error . Item ) {
207
+ throw new Error ( 'Item is undefined' ) ;
211
208
}
209
+ const Item = unmarshall ( error . Item ) ;
210
+ throw new IdempotencyItemAlreadyExistsError (
211
+ `Failed to put record for already existing idempotency key: ${ record . idempotencyKey } ` ,
212
+ new IdempotencyRecord ( {
213
+ idempotencyKey : Item [ this . keyAttr ] ,
214
+ status : Item [ this . statusAttr ] ,
215
+ expiryTimestamp : Item [ this . expiryAttr ] ,
216
+ inProgressExpiryTimestamp : Item [ this . inProgressExpiryAttr ] ,
217
+ responseData : Item [ this . dataAttr ] ,
218
+ payloadHash : Item [ this . validationKeyAttr ] ,
219
+ } )
220
+ ) ;
212
221
}
213
222
}
214
223
You can’t perform that action at this time.
0 commit comments