Skip to content

Commit 01a604f

Browse files
committed
Merge branch 'main' into tolutheo-dev
2 parents 8c0714f + 755a3e0 commit 01a604f

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,
@@ -201,24 +200,22 @@ class DynamoDBPersistenceLayer extends BasePersistenceLayer {
201200
})
202201
);
203202
} catch (error) {
204-
if (error instanceof DynamoDBServiceException) {
205-
if (error instanceof ConditionalCheckFailedException) {
206-
if (!error.Item) {
207-
throw new Error('Item is undefined');
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-
);
203+
if (error instanceof ConditionalCheckFailedException) {
204+
if (!error.Item) {
205+
throw new Error('item is undefined');
221206
}
207+
const item = unmarshall(error.Item);
208+
throw new IdempotencyItemAlreadyExistsError(
209+
`Failed to put record for already existing idempotency key: ${record.idempotencyKey}`,
210+
new IdempotencyRecord({
211+
idempotencyKey: item[this.keyAttr],
212+
status: item[this.statusAttr],
213+
expiryTimestamp: item[this.expiryAttr],
214+
inProgressExpiryTimestamp: item[this.inProgressExpiryAttr],
215+
responseData: item[this.dataAttr],
216+
payloadHash: item[this.validationKeyAttr],
217+
})
218+
);
222219
}
223220

224221
throw error;

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)