Skip to content

Commit

Permalink
fix(idempotency): include cause in idempotency persistence layer error (
Browse files Browse the repository at this point in the history
#2916)

Co-authored-by: Alexander Schueren <sha@amazon.com>
  • Loading branch information
dreamorosi and am29d authored Aug 13, 2024
1 parent 64fbb29 commit 47f0161
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 0 additions & 2 deletions packages/idempotency/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ class IdempotencyInconsistentStateError extends IdempotencyUnknownError {
* Unrecoverable error from the data store
*/
class IdempotencyPersistenceLayerError extends IdempotencyUnknownError {
public readonly cause: Error | undefined;

public constructor(message: string, options?: ErrorOptions) {
super(message, options);
this.name = 'IdempotencyPersistenceLayerError';
Expand Down
27 changes: 13 additions & 14 deletions packages/idempotency/tests/unit/IdempotencyHandler.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* Test Idempotency Handler
*
* @group unit/idempotency/IdempotencyHandler
*/
import { IdempotencyRecord } from '../../src/persistence/index.js';
import { IdempotencyHandler } from '../../src/IdempotencyHandler.js';
import { IdempotencyRecordStatus, MAX_RETRIES } from '../../src/constants.js';
import {
IdempotencyConfig,
IdempotencyAlreadyInProgressError,
IdempotencyConfig,
IdempotencyInconsistentStateError,
IdempotencyItemAlreadyExistsError,
IdempotencyPersistenceLayerError,
} from '../../src/index.js';
import { MAX_RETRIES, IdempotencyRecordStatus } from '../../src/constants.js';
/**
* Test Idempotency Handler
*
* @group unit/idempotency/IdempotencyHandler
*/
import { IdempotencyRecord } from '../../src/persistence/index.js';
import { PersistenceLayerTestClass } from '../helpers/idempotencyUtils.js';

const mockFunctionToMakeIdempotent = jest.fn();
Expand Down Expand Up @@ -198,12 +198,11 @@ describe('Class IdempotencyHandler', () => {
.mockRejectedValue(new Error('Some error'));

// Act & Assess
await expect(idempotentHandler.getFunctionResult()).rejects.toThrow(
new IdempotencyPersistenceLayerError(
'Failed to delete record from idempotency store',
new Error('Some error')
)
);
await expect(idempotentHandler.getFunctionResult()).rejects.toThrow({
name: 'IdempotencyPersistenceLayerError',
message: 'Failed to delete record from idempotency store',
cause: new Error('Some error'),
});
expect(mockDeleteInProgress).toHaveBeenCalledTimes(1);
});

Expand Down
3 changes: 3 additions & 0 deletions packages/idempotency/tests/unit/makeIdempotent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ describe('Function: makeIdempotent', () => {
await expect(handler(event, context)).rejects.toThrow({
name: 'IdempotencyPersistenceLayerError',
message: 'Failed to save in progress record to idempotency store',
cause: new Error('Something went wrong'),
});
}
);
Expand All @@ -166,6 +167,7 @@ describe('Function: makeIdempotent', () => {
await expect(handler(event, context)).rejects.toThrow({
name: 'IdempotencyPersistenceLayerError',
message: 'Failed to update success record to idempotency store',
cause: new Error('Something went wrong'),
});
}
);
Expand All @@ -186,6 +188,7 @@ describe('Function: makeIdempotent', () => {
await expect(handler(event, context)).rejects.toThrow({
name: 'IdempotencyPersistenceLayerError',
message: 'Failed to delete record from idempotency store',
cause: new Error('Something went wrong'),
});
}
);
Expand Down

0 comments on commit 47f0161

Please sign in to comment.