Skip to content

Commit e601d9d

Browse files
tolutheodreamorosi
authored andcommitted
pull request corrections
1 parent 2e2c79f commit e601d9d

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

packages/idempotency/src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IdempotencyRecord } from './persistence';
1+
import type { IdempotencyRecord } from './persistence';
22
/**
33
* Item attempting to be inserted into persistence store already exists and is not expired
44
*/

packages/idempotency/src/persistence/DynamoDBPersistenceLayer.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
DeleteItemCommand,
1111
DynamoDBClient,
1212
DynamoDBClientConfig,
13-
DynamoDBServiceException,
1413
GetItemCommand,
1514
PutItemCommand,
1615
UpdateItemCommand,
@@ -203,24 +202,22 @@ class DynamoDBPersistenceLayer extends BasePersistenceLayer {
203202
})
204203
);
205204
} catch (error) {
206-
if (error instanceof DynamoDBServiceException) {
207-
if (error instanceof ConditionalCheckFailedException) {
208-
if (!error.Item) {
209-
throw new Error('Item is undefined');
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-
);
205+
if (error instanceof ConditionalCheckFailedException) {
206+
if (!error.Item) {
207+
throw new Error('item is undefined');
223208
}
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+
);
224221
}
225222
}
226223
}

packages/idempotency/tests/unit/persistence/DynamoDbPersistenceLayer.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ import { IdempotencyRecord } from '../../../src/persistence';
1212
import type { DynamoDBPersistenceOptions } from '../../../src/types';
1313
import { IdempotencyRecordStatus } from '../../../src';
1414
import {
15+
ConditionalCheckFailedException,
1516
DynamoDBClient,
16-
//DynamoDBServiceException,
1717
PutItemCommand,
1818
GetItemCommand,
1919
UpdateItemCommand,
2020
DeleteItemCommand,
21-
ConditionalCheckFailedException,
2221
} from '@aws-sdk/client-dynamodb';
2322
import { marshall } from '@aws-sdk/util-dynamodb';
2423
import { mockClient } from 'aws-sdk-client-mock';
@@ -397,7 +396,6 @@ describe('Class: DynamoDBPersistenceLayer', () => {
397396
});
398397
client.on(PutItemCommand).rejects(
399398
new ConditionalCheckFailedException({
400-
//$fault: 'client',
401399
$metadata: {
402400
httpStatusCode: 400,
403401
requestId: 'someRequestId',
@@ -408,7 +406,6 @@ describe('Class: DynamoDBPersistenceLayer', () => {
408406
status: { S: 'INPROGRESS' },
409407
expiration: { N: Date.now().toString() },
410408
},
411-
//name: 'ConditionalCheckFailedException',
412409
})
413410
);
414411

@@ -710,7 +707,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
710707
})
711708
);
712709
await expect(persistenceLayer._putRecord(mockRecord)).rejects.toThrowError(
713-
'Item is undefined'
710+
'item is undefined'
714711
);
715712
});
716713
});

0 commit comments

Comments
 (0)