Skip to content

Commit bd318c5

Browse files
committed
fix(idempotency): include cause in idempotency persistence layer error
1 parent 9e5fa64 commit bd318c5

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

Diff for: packages/idempotency/src/errors.ts

-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ class IdempotencyInconsistentStateError extends IdempotencyUnknownError {
9797
* Unrecoverable error from the data store
9898
*/
9999
class IdempotencyPersistenceLayerError extends IdempotencyUnknownError {
100-
public readonly cause: Error | undefined;
101-
102100
public constructor(message: string, options?: ErrorOptions) {
103101
super(message, options);
104102
this.name = 'IdempotencyPersistenceLayerError';

Diff for: packages/idempotency/tests/unit/IdempotencyHandler.test.ts

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
/**
2-
* Test Idempotency Handler
3-
*
4-
* @group unit/idempotency/IdempotencyHandler
5-
*/
6-
import { IdempotencyRecord } from '../../src/persistence/index.js';
71
import { IdempotencyHandler } from '../../src/IdempotencyHandler.js';
2+
import { IdempotencyRecordStatus, MAX_RETRIES } from '../../src/constants.js';
83
import {
9-
IdempotencyConfig,
104
IdempotencyAlreadyInProgressError,
5+
IdempotencyConfig,
116
IdempotencyInconsistentStateError,
127
IdempotencyItemAlreadyExistsError,
138
IdempotencyPersistenceLayerError,
149
} from '../../src/index.js';
15-
import { MAX_RETRIES, IdempotencyRecordStatus } from '../../src/constants.js';
10+
/**
11+
* Test Idempotency Handler
12+
*
13+
* @group unit/idempotency/IdempotencyHandler
14+
*/
15+
import { IdempotencyRecord } from '../../src/persistence/index.js';
1616
import { PersistenceLayerTestClass } from '../helpers/idempotencyUtils.js';
1717

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

200200
// Act & Assess
201-
await expect(idempotentHandler.getFunctionResult()).rejects.toThrow(
202-
new IdempotencyPersistenceLayerError(
203-
'Failed to delete record from idempotency store',
204-
new Error('Some error')
205-
)
206-
);
201+
await expect(idempotentHandler.getFunctionResult()).rejects.toThrow({
202+
name: 'IdempotencyPersistenceLayerError',
203+
message: 'Failed to delete record from idempotency store',
204+
cause: new Error('Some error'),
205+
});
207206
expect(mockDeleteInProgress).toHaveBeenCalledTimes(1);
208207
});
209208

Diff for: packages/idempotency/tests/unit/makeIdempotent.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ describe('Function: makeIdempotent', () => {
144144
await expect(handler(event, context)).rejects.toThrow({
145145
name: 'IdempotencyPersistenceLayerError',
146146
message: 'Failed to save in progress record to idempotency store',
147+
cause: new Error('Something went wrong'),
147148
});
148149
}
149150
);
@@ -166,6 +167,7 @@ describe('Function: makeIdempotent', () => {
166167
await expect(handler(event, context)).rejects.toThrow({
167168
name: 'IdempotencyPersistenceLayerError',
168169
message: 'Failed to update success record to idempotency store',
170+
cause: new Error('Something went wrong'),
169171
});
170172
}
171173
);
@@ -186,6 +188,7 @@ describe('Function: makeIdempotent', () => {
186188
await expect(handler(event, context)).rejects.toThrow({
187189
name: 'IdempotencyPersistenceLayerError',
188190
message: 'Failed to delete record from idempotency store',
191+
cause: new Error('Something went wrong'),
189192
});
190193
}
191194
);

0 commit comments

Comments
 (0)