Skip to content

Commit d4f18e7

Browse files
committed
fix(idempotency): include cause in idempotency persistence layer error
1 parent 4a87213 commit d4f18e7

File tree

4 files changed

+43
-52
lines changed

4 files changed

+43
-52
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/makeHandlerIdempotent.test.ts

+15-18
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ describe('Middleware: makeHandlerIdempotent', () => {
112112
.mockRejectedValue(new Error('Something went wrong'));
113113

114114
// Act && Assess
115-
await expect(handler(event, context)).rejects.toThrowError(
116-
new IdempotencyPersistenceLayerError(
117-
'Failed to save in progress record to idempotency store',
118-
new Error('Something went wrong')
119-
)
120-
);
115+
await expect(handler(event, context)).rejects.toThrow({
116+
name: 'IdempotencyPersistenceLayerError',
117+
message: 'Failed to save in progress record to idempotency store',
118+
cause: new Error('Something went wrong'),
119+
});
121120
});
122121
it('thows an error if the persistence layer throws an error when saving a successful operation', async () => {
123122
// Prepare
@@ -129,12 +128,11 @@ describe('Middleware: makeHandlerIdempotent', () => {
129128
.mockRejectedValue(new Error('Something went wrong'));
130129

131130
// Act && Assess
132-
await expect(handler(event, context)).rejects.toThrowError(
133-
new IdempotencyPersistenceLayerError(
134-
'Failed to update success record to idempotency store',
135-
new Error('Something went wrong')
136-
)
137-
);
131+
await expect(handler(event, context)).rejects.toThrow({
132+
name: 'IdempotencyPersistenceLayerError',
133+
message: 'Failed to update success record to idempotency store',
134+
cause: new Error('Something went wrong'),
135+
});
138136
});
139137
it('thows an error if the persistence layer throws an error when deleting a record', async () => {
140138
// Prepare
@@ -148,12 +146,11 @@ describe('Middleware: makeHandlerIdempotent', () => {
148146
.mockRejectedValue(new Error('Something went wrong'));
149147

150148
// Act && Assess
151-
await expect(handler(event, context)).rejects.toThrow(
152-
new IdempotencyPersistenceLayerError(
153-
'Failed to delete record from idempotency store',
154-
new Error('Something went wrong')
155-
)
156-
);
149+
await expect(handler(event, context)).rejects.toThrow({
150+
name: 'IdempotencyPersistenceLayerError',
151+
message: 'Failed to delete record from idempotency store',
152+
cause: new Error('Something went wrong'),
153+
});
157154
});
158155
it('returns the stored response if the operation has already been executed', async () => {
159156
// Prepare

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

+15-18
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ describe('Function: makeIdempotent', () => {
118118
.mockRejectedValue(new Error('Something went wrong'));
119119

120120
// Act && Assess
121-
await expect(handler(event, context)).rejects.toThrowError(
122-
new IdempotencyPersistenceLayerError(
123-
'Failed to save in progress record to idempotency store',
124-
new Error('Something went wrong')
125-
)
126-
);
121+
await expect(handler(event, context)).rejects.toThrow({
122+
name: 'IdempotencyPersistenceLayerError',
123+
message: 'Failed to save in progress record to idempotency store',
124+
cause: new Error('Something went wrong'),
125+
});
127126
});
128127
it('thows an error if the persistence layer throws an error when saving a successful operation', async () => {
129128
// Prepare
@@ -139,12 +138,11 @@ describe('Function: makeIdempotent', () => {
139138
.mockRejectedValue(new Error('Something went wrong'));
140139

141140
// Act && Assess
142-
await expect(handler(event, context)).rejects.toThrowError(
143-
new IdempotencyPersistenceLayerError(
144-
'Failed to update success record to idempotency store',
145-
new Error('Something went wrong')
146-
)
147-
);
141+
await expect(handler(event, context)).rejects.toThrow({
142+
name: 'IdempotencyPersistenceLayerError',
143+
message: 'Failed to update success record to idempotency store',
144+
cause: new Error('Something went wrong'),
145+
});
148146
});
149147
it('thows an error if the persistence layer throws an error when deleting a record', async () => {
150148
// Prepare
@@ -162,12 +160,11 @@ describe('Function: makeIdempotent', () => {
162160
.mockRejectedValue(new Error('Something went wrong'));
163161

164162
// Act && Assess
165-
await expect(handler(event, context)).rejects.toThrow(
166-
new IdempotencyPersistenceLayerError(
167-
'Failed to delete record from idempotency store',
168-
new Error('Something went wrong')
169-
)
170-
);
163+
await expect(handler(event, context)).rejects.toThrow({
164+
name: 'IdempotencyPersistenceLayerError',
165+
message: 'Failed to delete record from idempotency store',
166+
cause: new Error('Something went wrong'),
167+
});
171168
});
172169
it('returns the stored response if the operation has already been executed', async () => {
173170
// Prepare

0 commit comments

Comments
 (0)