Skip to content

Commit 40b4c63

Browse files
fix: align with TransportError class from squash-merged SDK-84
The squash merge of PR #2839 changed TransportError from an interface to a class extending Error. Update test fixtures and the partial-success detection in httpSend to use `new TransportError(...)` instead of plain object literals. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d6d9a68 commit 40b4c63

4 files changed

Lines changed: 25 additions & 22 deletions

File tree

packages/audience/core/src/consent.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createConsentManager } from './consent';
22
import type { HttpSend } from './transport';
3+
import { TransportError } from './errors';
34

45
function createMockSend() {
56
return jest.fn<ReturnType<HttpSend>, Parameters<HttpSend>>().mockResolvedValue({ ok: true });
@@ -123,11 +124,11 @@ describe('createConsentManager', () => {
123124
const queue = createMockQueue();
124125
const send = jest.fn<ReturnType<HttpSend>, Parameters<HttpSend>>().mockResolvedValue({
125126
ok: false,
126-
error: {
127+
error: new TransportError({
127128
status: 503,
128129
endpoint: 'https://api.dev.immutable.com/v1/audience/tracking-consent',
129130
body: { code: 'SERVICE_UNAVAILABLE' },
130-
},
131+
}),
131132
});
132133
const onError = jest.fn();
133134
const manager = createConsentManager(queue, send, 'pk_test', 'anon-1', 'dev', 'pixel', 'none', onError);
@@ -149,11 +150,11 @@ describe('createConsentManager', () => {
149150
const queue = createMockQueue();
150151
const send = jest.fn<ReturnType<HttpSend>, Parameters<HttpSend>>().mockResolvedValue({
151152
ok: false,
152-
error: {
153+
error: new TransportError({
153154
status: 0,
154155
endpoint: 'https://api.dev.immutable.com/v1/audience/tracking-consent',
155156
cause: new TypeError('Failed to fetch'),
156-
},
157+
}),
157158
});
158159
const onError = jest.fn();
159160
const manager = createConsentManager(queue, send, 'pk_test', 'anon-1', 'dev', 'pixel', 'none', onError);
@@ -185,7 +186,7 @@ describe('createConsentManager', () => {
185186
const queue = createMockQueue();
186187
const send = jest.fn<ReturnType<HttpSend>, Parameters<HttpSend>>().mockResolvedValue({
187188
ok: false,
188-
error: { status: 500, endpoint: 'x', body: null },
189+
error: new TransportError({ status: 500, endpoint: 'x', body: null }),
189190
});
190191
const onError = jest.fn().mockImplementation(() => { throw new Error('callback boom'); });
191192
const manager = createConsentManager(queue, send, 'pk_test', 'anon-1', 'dev', 'pixel', 'none', onError);

packages/audience/core/src/errors.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
AudienceError, toAudienceError, type TransportError,
2+
AudienceError, TransportError, toAudienceError,
33
} from './errors';
44

55
describe('AudienceError', () => {
@@ -37,17 +37,17 @@ describe('AudienceError', () => {
3737
});
3838

3939
describe('toAudienceError', () => {
40-
const httpError: TransportError = {
40+
const httpError = new TransportError({
4141
status: 500,
4242
endpoint: 'https://api.dev.immutable.com/v1/audience/messages',
4343
body: { code: 'INTERNAL_ERROR' },
44-
};
44+
});
4545

46-
const networkError: TransportError = {
46+
const networkError = new TransportError({
4747
status: 0,
4848
endpoint: 'https://api.dev.immutable.com/v1/audience/messages',
4949
cause: new TypeError('Failed to fetch'),
50-
};
50+
});
5151

5252
describe('flush source', () => {
5353
it('maps HTTP error to FLUSH_FAILED with status in message', () => {
@@ -98,11 +98,11 @@ describe('toAudienceError', () => {
9898

9999
describe('partial-rejection (2xx with rejected > 0)', () => {
100100
it('maps to VALIDATION_REJECTED with backend body preserved', () => {
101-
const partialError: TransportError = {
101+
const partialError = new TransportError({
102102
status: 200,
103103
endpoint: 'https://api.dev.immutable.com/v1/audience/messages',
104104
body: { accepted: 50, rejected: 50 },
105-
};
105+
});
106106

107107
const err = toAudienceError(partialError, 'flush', 100);
108108

@@ -113,11 +113,11 @@ describe('toAudienceError', () => {
113113
});
114114

115115
it('handles missing accepted/rejected fields gracefully', () => {
116-
const partialError: TransportError = {
116+
const partialError = new TransportError({
117117
status: 200,
118118
endpoint: 'https://api.dev.immutable.com/v1/audience/messages',
119119
body: {},
120-
};
120+
});
121121

122122
const err = toAudienceError(partialError, 'flush');
123123

packages/audience/core/src/queue.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MessageQueue } from './queue';
22
import type { HttpSend } from './transport';
3-
import type { AudienceError, TransportResult } from './errors';
3+
import { TransportError, type AudienceError, type TransportResult } from './errors';
44
import type { Message } from './types';
55
import * as storage from './storage';
66

@@ -206,7 +206,9 @@ describe('MessageQueue', () => {
206206
const onError = jest.fn();
207207
const send = jest.fn<ReturnType<HttpSend>, Parameters<HttpSend>>().mockResolvedValue({
208208
ok: false,
209-
error: { status: 500, endpoint: 'https://api.immutable.com/v1/audience/messages', body: null },
209+
error: new TransportError({
210+
status: 500, endpoint: 'https://api.immutable.com/v1/audience/messages', body: null,
211+
}),
210212
});
211213
const queue = createQueue(send, { onError });
212214

@@ -225,11 +227,11 @@ describe('MessageQueue', () => {
225227
const onError = jest.fn();
226228
const send = jest.fn<ReturnType<HttpSend>, Parameters<HttpSend>>().mockResolvedValue({
227229
ok: false,
228-
error: {
230+
error: new TransportError({
229231
status: 0,
230232
endpoint: 'https://api.immutable.com/v1/audience/messages',
231233
cause: new TypeError('Failed to fetch'),
232-
},
234+
}),
233235
});
234236
const queue = createQueue(send, { onError });
235237

@@ -275,11 +277,11 @@ describe('MessageQueue', () => {
275277
const onError = jest.fn();
276278
const send = jest.fn<ReturnType<HttpSend>, Parameters<HttpSend>>().mockResolvedValue({
277279
ok: false,
278-
error: {
280+
error: new TransportError({
279281
status: 200,
280282
endpoint: 'https://api.immutable.com/v1/audience/messages',
281283
body: { accepted: 1, rejected: 1 },
282-
},
284+
}),
283285
});
284286
const queue = createQueue(send, { onError });
285287

packages/audience/core/src/transport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ export const httpSend: HttpSend = async (
8282
});
8383
return {
8484
ok: false,
85-
error: {
85+
error: new TransportError({
8686
status: response.status,
8787
endpoint: url,
8888
body: bodyObj,
89-
},
89+
}),
9090
};
9191
}
9292

0 commit comments

Comments
 (0)