@sgedda/mockifyer-fetch 1.8.46 → 1.8.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Whether `status` forbids a Response body under the Fetch spec.
3
+ */
4
+ export declare function isFetchNullBodyStatus(status: number): boolean;
5
+ /**
6
+ * Body argument for `new Response(body, { status })`.
7
+ * Returns `null` for null-body statuses so Node/undici does not throw.
8
+ */
9
+ export declare function bodyInitForFetchResponse(status: number, data: unknown): BodyInit | null;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFetchNullBodyStatus = isFetchNullBodyStatus;
4
+ exports.bodyInitForFetchResponse = bodyInitForFetchResponse;
5
+ /**
6
+ * Fetch "null body status" codes — Response body must be null.
7
+ * Passing '' / JSON (including JSON.stringify(null) → "null") throws in undici:
8
+ * `TypeError: Response constructor: Invalid response status code 204`
9
+ *
10
+ * @see https://fetch.spec.whatwg.org/#null-body-status
11
+ */
12
+ const FETCH_NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);
13
+ /**
14
+ * Whether `status` forbids a Response body under the Fetch spec.
15
+ */
16
+ function isFetchNullBodyStatus(status) {
17
+ return FETCH_NULL_BODY_STATUSES.has(status);
18
+ }
19
+ /**
20
+ * Body argument for `new Response(body, { status })`.
21
+ * Returns `null` for null-body statuses so Node/undici does not throw.
22
+ */
23
+ function bodyInitForFetchResponse(status, data) {
24
+ if (isFetchNullBodyStatus(status)) {
25
+ return null;
26
+ }
27
+ if (typeof data === 'string') {
28
+ return data;
29
+ }
30
+ // JSON.stringify(undefined) is undefined — Response treats nullish as empty body
31
+ if (data === undefined) {
32
+ return null;
33
+ }
34
+ return JSON.stringify(data);
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sgedda/mockifyer-fetch",
3
- "version": "1.8.46",
3
+ "version": "1.8.71",
4
4
  "description": "Mockifyer for Fetch - API mocking and logging utility for storing and replaying API responses",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "license": "MIT",
51
51
  "dependencies": {
52
- "@sgedda/mockifyer-core": "^1.10.31"
52
+ "@sgedda/mockifyer-core": "^1.10.142"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^20.11.24",
@@ -8,6 +8,7 @@ import {
8
8
  getOutboundMockifyerDeviceIdHeader,
9
9
  MOCKIFYER_CLIENT_ID_HEADER,
10
10
  MOCKIFYER_DEVICE_ID_HEADER,
11
+ resolveMockifyerTraceFromHeaders,
11
12
  } from '@sgedda/mockifyer-core';
12
13
  import { performDashboardProxyRequest } from '../core-proxy';
13
14
 
@@ -188,12 +189,15 @@ export class FetchHTTPClient extends BaseHTTPClient<any, HTTPResponse<any>> {
188
189
  responseHeaders[key] = value;
189
190
  });
190
191
 
192
+ const mockifyerTrace = resolveMockifyerTraceFromHeaders(responseHeaders);
193
+
191
194
  return {
192
195
  data,
193
196
  status: response.status,
194
197
  statusText: response.statusText,
195
198
  headers: responseHeaders,
196
199
  config,
200
+ ...(mockifyerTrace ? { mockifyerTrace } : {}),
197
201
  };
198
202
  }
199
203
 
package/src/index.ts CHANGED
@@ -43,7 +43,7 @@ import {
43
43
  type PoolResponseItem,
44
44
  shouldBypassMockifyerForUrl,
45
45
  containsMockifyerSyncEndpointMarker,
46
- isMockifyerDashboardProxyApiUrl,
46
+ isMockifyerDashboardPlumbingApiUrl,
47
47
  resolveRecordingExclusions,
48
48
  shouldExcludeRecording,
49
49
  mockPassesThroughToRealApi,
@@ -58,6 +58,7 @@ import {
58
58
  resolveExplicitClientIdOnly,
59
59
  resolveProxyStrictLaneScenario,
60
60
  registerMockifyerInstance,
61
+ ensureOverrideGroupRuntimeForScenarioPath,
61
62
  logMockifyerInitSummary,
62
63
  tryGetClientIdFromLaunchArguments,
63
64
  MOCKIFYER_LAUNCH_ARGUMENT_CLIENT_ID_KEY,
@@ -76,11 +77,19 @@ import {
76
77
  getInlineTraceEnvelopeBusinessBody,
77
78
  resolveRecordResponses,
78
79
  applyOutboundRequestCorrelation,
80
+ adoptStoredOutboundRequestId,
81
+ resolvePersistedHopIds,
79
82
  attachMockifyerRequestIdToError,
80
83
  resolveMockifyerRequestIdForError,
84
+ configureFlightRecorder,
85
+ resolveFlightRecorderConfig,
86
+ setFlightRecorderRuntimeContext,
87
+ configureAtlas,
88
+ resolveActiveMockifyerSessionId,
81
89
  type RequestCorrelationContext,
82
90
  DomainPathRulesSession,
83
91
  installNodeInboundRequestCorrelationCapture,
92
+ stripMockifyerTraceFromBody,
84
93
  } from '@sgedda/mockifyer-core';
85
94
  import { logger, setLogLevel } from '@sgedda/mockifyer-core';
86
95
  import {
@@ -100,6 +109,7 @@ import {
100
109
  import { resolveProxyUpstreamTlsInsecure } from '@sgedda/mockifyer-core/utils/proxy-upstream-tls-insecure';
101
110
 
102
111
  import { FetchHTTPClient } from './clients/fetch-client';
112
+ import { bodyInitForFetchResponse } from './utils/fetch-response-body';
103
113
 
104
114
  class MockifyerClass {
105
115
  private config: MockifyerConfig;
@@ -121,19 +131,29 @@ class MockifyerClass {
121
131
  private readonly poolResponseCache = new Map<string, PoolResponseItem>();
122
132
  private readonly domainPathRules: DomainPathRulesSession;
123
133
 
124
- /** Best-effort dashboard network log (skipped when traffic goes through `proxy.baseUrl`). */
134
+ /** Session id for timeline hops — per-screen id from {@link setFlightRecorderRuntimeContext} when set. */
135
+ private getRuntimeSessionId(): string {
136
+ return resolveActiveMockifyerSessionId(() => {
137
+ const now = Date.now();
138
+ if (!this.currentSessionId || now - this.sessionStartTime > this.SESSION_TIMEOUT_MS) {
139
+ this.currentSessionId = `session-${now}-${Math.random().toString(36).substring(2, 11)}`;
140
+ this.sessionStartTime = now;
141
+ setFlightRecorderRuntimeContext({ sessionId: this.currentSessionId });
142
+ }
143
+ return this.currentSessionId;
144
+ });
145
+ }
146
+
147
+ /** Best-effort dashboard network log. */
125
148
  private logNetworkEvent(
126
149
  partial: Parameters<typeof emitMockifyerNetworkEvent>[0]['event'] & {
127
- transport?: 'fetch';
150
+ transport?: 'fetch' | 'proxy';
128
151
  /** Raw bodies for inline-trace / network-log previews (stripped before emit). */
129
152
  requestBody?: unknown;
130
153
  responseBody?: unknown;
131
154
  },
132
155
  correlation?: RequestCorrelationContext
133
156
  ): void {
134
- // Dashboard proxy hops are recorded in performDashboardProxyRequest (shared axios/fetch path).
135
- if (this.config.proxy?.baseUrl) return;
136
-
137
157
  const scenario =
138
158
  this.config.proxy?.scenario?.trim() ||
139
159
  getCurrentScenario(this.config.mockDataPath);
@@ -141,25 +161,30 @@ class MockifyerClass {
141
161
  const { requestBody, responseBody, ...eventPartial } = partial;
142
162
  const businessResponseBody = getInlineTraceEnvelopeBusinessBody(responseBody);
143
163
 
144
- recordInlineTraceHopFromExchange({
145
- method: eventPartial.method,
146
- url: eventPartial.url,
147
- status: eventPartial.status,
148
- source: eventPartial.source,
149
- transport: eventPartial.transport ?? 'fetch',
150
- requestId: correlation?.requestId ?? eventPartial.requestId ?? null,
151
- parentRequestId: correlation?.parentRequestId ?? eventPartial.parentRequestId ?? null,
152
- durationMs: eventPartial.durationMs,
153
- clientId: this.config.clientId ?? eventPartial.clientId ?? null,
154
- errorMessage: eventPartial.errorMessage,
155
- requestBody,
156
- responseBody,
157
- });
164
+ if (!this.config.proxy?.baseUrl) {
165
+ recordInlineTraceHopFromExchange({
166
+ method: eventPartial.method,
167
+ url: eventPartial.url,
168
+ status: eventPartial.status,
169
+ source: eventPartial.source,
170
+ transport: eventPartial.transport ?? 'fetch',
171
+ requestId: correlation?.requestId ?? eventPartial.requestId ?? null,
172
+ parentRequestId: correlation?.parentRequestId ?? eventPartial.parentRequestId ?? null,
173
+ durationMs: eventPartial.durationMs,
174
+ clientId: this.config.clientId ?? eventPartial.clientId ?? null,
175
+ errorMessage: eventPartial.errorMessage,
176
+ requestBody,
177
+ responseBody,
178
+ });
179
+ }
158
180
 
159
181
  emitMockifyerNetworkEvent({
160
182
  config: this.config,
161
183
  scenario,
162
184
  clientId: this.config.clientId,
185
+ sessionId: this.getRuntimeSessionId(),
186
+ requestBody,
187
+ responseBody: businessResponseBody,
163
188
  event: {
164
189
  ...eventPartial,
165
190
  transport: eventPartial.transport ?? 'fetch',
@@ -182,6 +207,22 @@ class MockifyerClass {
182
207
  correlation.parentRequestId;
183
208
  }
184
209
 
210
+ private bindStoredHopId(
211
+ config: unknown,
212
+ mockData: { requestId?: string } | undefined,
213
+ fallback?: RequestCorrelationContext
214
+ ): RequestCorrelationContext | undefined {
215
+ const adopted = adoptStoredOutboundRequestId(
216
+ config as { headers?: unknown },
217
+ mockData?.requestId
218
+ );
219
+ if (adopted) {
220
+ this.stashRequestCorrelation(config, adopted);
221
+ return adopted;
222
+ }
223
+ return fallback;
224
+ }
225
+
185
226
  private readRequestCorrelation(config: unknown): RequestCorrelationContext | undefined {
186
227
  const requestId = (config as { __mockifyer_requestId?: string }).__mockifyer_requestId;
187
228
  if (!requestId) return undefined;
@@ -205,7 +246,7 @@ class MockifyerClass {
205
246
  * Always passes `loadPoolResponse` — including React Native where Node `fs`/`path` are
206
247
  * missing or Metro-stubbed — so `$pool` refs resolve via disk and/or {@link poolResponseCache}.
207
248
  */
208
- private prepareStoredResponseBody(mockData: MockData): unknown {
249
+ private prepareStoredResponseBody(mockData: MockData, filename?: string, scenarioPath?: string): unknown {
209
250
  const joinPath =
210
251
  path && typeof path.join === 'function' ? path.join.bind(path) : null;
211
252
  return prepareMockResponseBody(mockData, getCurrentDate, {
@@ -215,6 +256,8 @@ class MockifyerClass {
215
256
  joinPath,
216
257
  cache: this.poolResponseCache,
217
258
  }),
259
+ filename,
260
+ scenarioPath,
218
261
  });
219
262
  }
220
263
 
@@ -370,6 +413,15 @@ class MockifyerClass {
370
413
  }
371
414
  this.activationMode = resolveActivationMode(this.config);
372
415
  this.domainPathRules = new DomainPathRulesSession({ config: this.config });
416
+ configureFlightRecorder(resolveFlightRecorderConfig(this.config));
417
+ configureAtlas(this.config, {
418
+ scenario: getCurrentScenario(this.config.mockDataPath, this.config.clientId),
419
+ clientId: this.config.clientId ?? null,
420
+ });
421
+ setFlightRecorderRuntimeContext({
422
+ clientId: this.config.clientId,
423
+ scenario: getCurrentScenario(this.config.mockDataPath, this.config.clientId),
424
+ });
373
425
 
374
426
  if (this.config.proxy?.baseUrl && this.config.proxy.mirrorRecordedMocksToClient === undefined) {
375
427
  const raw =
@@ -542,6 +594,7 @@ class MockifyerClass {
542
594
 
543
595
  const currentScenario = getCurrentScenario(resolvedMockDataPath, this.config.clientId);
544
596
  const scenarioPath = getScenarioFolderPath(resolvedMockDataPath, currentScenario);
597
+ ensureOverrideGroupRuntimeForScenarioPath(scenarioPath, { clientId: this.config.clientId });
545
598
 
546
599
  if (!fs.existsSync(scenarioPath)) {
547
600
  logger.warn('[Mockifyer-Fetch] ⚠️ Scenario path does not exist:', scenarioPath);
@@ -568,7 +621,13 @@ class MockifyerClass {
568
621
  const mockKey = this.generateRequestKey(mockData.request);
569
622
 
570
623
  if (mockKey === requestKey) {
571
- if (mockShouldBeIncludedInRequestMatch(mockData, { includePassthroughMocks })) {
624
+ if (
625
+ mockShouldBeIncludedInRequestMatch(mockData, {
626
+ includePassthroughMocks,
627
+ filename: file,
628
+ scenarioPath,
629
+ })
630
+ ) {
572
631
  exactMatch = { mockData, filename: file, filePath };
573
632
  break;
574
633
  }
@@ -648,7 +707,13 @@ class MockifyerClass {
648
707
  }
649
708
  }
650
709
 
651
- if (!mockPassesThroughToRealApi(mockData)) {
710
+ if (
711
+ mockShouldBeIncludedInRequestMatch(mockData, {
712
+ includePassthroughMocks,
713
+ filename: file,
714
+ scenarioPath,
715
+ })
716
+ ) {
652
717
  similarMatch = { mockData, filename: file, filePath };
653
718
  }
654
719
  }
@@ -711,7 +776,7 @@ class MockifyerClass {
711
776
  return config;
712
777
  }
713
778
 
714
- const correlation = applyOutboundRequestCorrelation(config);
779
+ let correlation = applyOutboundRequestCorrelation(config);
715
780
  this.stashRequestCorrelation(config, correlation);
716
781
 
717
782
  // Normalize empty params: treat {} the same as undefined for consistent matching
@@ -759,12 +824,22 @@ class MockifyerClass {
759
824
 
760
825
  if (cachedMock) {
761
826
  const { mockData, filename, filePath } = cachedMock;
827
+ correlation = this.bindStoredHopId(config, mockData, correlation) ?? correlation;
762
828
  if (mockShouldServeStoredBody(mockData)) {
763
829
  logger.info(
764
830
  `[Mockifyer-Fetch] Mock hit: ${request.method} ${request.url} → ${filename}` +
765
831
  (filePath ? ` (${filePath})` : '')
766
832
  );
767
- const mockResponseBody = this.prepareStoredResponseBody(mockData);
833
+ const hitScenarioPath = path
834
+ ? getScenarioFolderPath(
835
+ path.resolve(this.config.mockDataPath),
836
+ getCurrentScenario(path.resolve(this.config.mockDataPath), this.config.clientId)
837
+ )
838
+ : undefined;
839
+ if (hitScenarioPath) {
840
+ ensureOverrideGroupRuntimeForScenarioPath(hitScenarioPath, { clientId: this.config.clientId });
841
+ }
842
+ const mockResponseBody = this.prepareStoredResponseBody(mockData, filename, hitScenarioPath);
768
843
  this.logNetworkEvent(
769
844
  {
770
845
  method: (request.method || 'GET').toUpperCase(),
@@ -932,6 +1007,39 @@ class MockifyerClass {
932
1007
  const isMocked = response.headers && (response.headers as any)['x-mockifyer'] === 'true';
933
1008
  const isLimitReached = response.headers && (response.headers as any)['x-mockifyer-limit-reached'] === 'true';
934
1009
  if (isMocked || isLimitReached) {
1010
+ // Local mock hits are logged in the request interceptor; proxy mock hits must
1011
+ // be recorded here before early return (otherwise flight recorder stays empty).
1012
+ const shouldLogMockOrLimit =
1013
+ isLimitReached || (isMocked && this.usesDashboardProxy());
1014
+ if (shouldLogMockOrLimit) {
1015
+ const reqUrl = response.config?.url || url;
1016
+ const reqMethod = (response.config?.method || 'GET').toUpperCase();
1017
+ const startTime = (response.config as any).__mockifyer_startTime;
1018
+ const durationMs = startTime ? Date.now() - startTime : undefined;
1019
+ this.logNetworkEvent(
1020
+ {
1021
+ method: reqMethod,
1022
+ url: reqUrl,
1023
+ source: isLimitReached ? 'error' : 'mock-hit',
1024
+ status: response.status,
1025
+ durationMs,
1026
+ transport: this.usesDashboardProxy() ? 'proxy' : 'fetch',
1027
+ requestBody: response.config?.data,
1028
+ responseBody: response.data,
1029
+ ...(isLimitReached
1030
+ ? {
1031
+ errorMessage:
1032
+ typeof response.data === 'object' &&
1033
+ response.data !== null &&
1034
+ 'message' in response.data
1035
+ ? String((response.data as { message?: unknown }).message)
1036
+ : 'Request limit reached',
1037
+ }
1038
+ : {}),
1039
+ },
1040
+ this.readRequestCorrelation(response.config)
1041
+ );
1042
+ }
935
1043
  return response;
936
1044
  }
937
1045
 
@@ -963,18 +1071,33 @@ class MockifyerClass {
963
1071
 
964
1072
  const capturedResponse: StoredResponse = {
965
1073
  status: response.status,
966
- data: response.data,
1074
+ data: stripMockifyerTraceFromBody(response.data),
967
1075
  headers: (response.headers as Record<string, string>) || {},
968
1076
  };
969
1077
 
970
1078
  if (resolveShouldPersistLiveCapture(matchedMock.mockData, this.config)) {
971
- await this.persistMatchedMockAfterLiveCapture(matchedMock, capturedResponse, durationMs);
1079
+ await this.persistMatchedMockAfterLiveCapture(
1080
+ matchedMock,
1081
+ capturedResponse,
1082
+ durationMs,
1083
+ this.readRequestCorrelation(response.config)
1084
+ );
972
1085
  }
973
1086
 
1087
+ const liveScenarioPath = path
1088
+ ? getScenarioFolderPath(
1089
+ path.resolve(this.config.mockDataPath),
1090
+ getCurrentScenario(path.resolve(this.config.mockDataPath), this.config.clientId)
1091
+ )
1092
+ : undefined;
1093
+ if (liveScenarioPath) {
1094
+ ensureOverrideGroupRuntimeForScenarioPath(liveScenarioPath, { clientId: this.config.clientId });
1095
+ }
974
1096
  const clientResponse = buildClientResponseFromLiveCapture(
975
1097
  matchedMock.mockData,
976
1098
  capturedResponse,
977
- getCurrentDate
1099
+ getCurrentDate,
1100
+ { filename: matchedMock.filename, scenarioPath: liveScenarioPath }
978
1101
  );
979
1102
  response.data = clientResponse.data;
980
1103
  response.status = clientResponse.status;
@@ -1235,6 +1358,10 @@ class MockifyerClass {
1235
1358
  const duration = startTime ? Date.now() - startTime : undefined;
1236
1359
 
1237
1360
  const correlation = this.readRequestCorrelation(response.config);
1361
+ const hopIds = resolvePersistedHopIds(
1362
+ saveDecision.action === 'overwrite' ? existingMock?.mockData : undefined,
1363
+ correlation
1364
+ );
1238
1365
 
1239
1366
  const mockData: MockData = {
1240
1367
  request: {
@@ -1246,7 +1373,7 @@ class MockifyerClass {
1246
1373
  },
1247
1374
  response: {
1248
1375
  status: response.status,
1249
- data: response.data,
1376
+ data: stripMockifyerTraceFromBody(response.data),
1250
1377
  headers: response.headers || {},
1251
1378
  },
1252
1379
  timestamp: new Date().toISOString(),
@@ -1255,8 +1382,8 @@ class MockifyerClass {
1255
1382
  saveDecision.action === 'overwrite' && existingMock?.mockData.sessionId
1256
1383
  ? existingMock.mockData.sessionId
1257
1384
  : this.currentSessionId,
1258
- requestId: correlation?.requestId,
1259
- parentRequestId: correlation?.parentRequestId,
1385
+ requestId: hopIds.requestId,
1386
+ parentRequestId: hopIds.parentRequestId,
1260
1387
  ...(newRecordingUsesAlwaysUseRealApi() ? { alwaysUseRealApi: true as const } : {}),
1261
1388
  };
1262
1389
 
@@ -1317,9 +1444,19 @@ class MockifyerClass {
1317
1444
  private async persistMatchedMockAfterLiveCapture(
1318
1445
  cachedMock: CachedMockData,
1319
1446
  capturedResponse: StoredResponse,
1320
- durationMs?: number
1447
+ durationMs?: number,
1448
+ liveCorrelation?: RequestCorrelationContext
1321
1449
  ): Promise<void> {
1322
1450
  const updated = buildMockDataAfterLiveCapture(cachedMock.mockData, capturedResponse, durationMs);
1451
+ const hopIds = resolvePersistedHopIds(cachedMock.mockData, liveCorrelation);
1452
+ if (hopIds.requestId) {
1453
+ updated.requestId = hopIds.requestId;
1454
+ }
1455
+ if (hopIds.parentRequestId) {
1456
+ updated.parentRequestId = hopIds.parentRequestId;
1457
+ } else {
1458
+ delete updated.parentRequestId;
1459
+ }
1323
1460
 
1324
1461
  if (this.databaseProvider) {
1325
1462
  await this.databaseProvider.save(updated);
@@ -1654,11 +1791,11 @@ export function setupMockifyer(config: MockifyerConfig): MockifyerInstance {
1654
1791
  const headers = init?.headers || {};
1655
1792
  const body = init?.body;
1656
1793
 
1657
- // Skip Mockifyer sync endpoints, dashboard `/api/proxy` plumbing, and Resend API
1794
+ // Skip Mockifyer sync endpoints, dashboard plumbing, and Resend API
1658
1795
  if (
1659
1796
  containsMockifyerSyncEndpointMarker(url) ||
1660
1797
  url.includes('api.resend.com') ||
1661
- isMockifyerDashboardProxyApiUrl(url)
1798
+ isMockifyerDashboardPlumbingApiUrl(url)
1662
1799
  ) {
1663
1800
  return await originalFetchForPatched(input, init);
1664
1801
  }
@@ -1695,7 +1832,7 @@ export function setupMockifyer(config: MockifyerConfig): MockifyerInstance {
1695
1832
  headersObj[key] = value;
1696
1833
  });
1697
1834
  } else {
1698
- headersObj = headers as Record<string, string>;
1835
+ headersObj = { ...(headers as Record<string, string>) };
1699
1836
  }
1700
1837
 
1701
1838
  try {
@@ -1719,9 +1856,7 @@ export function setupMockifyer(config: MockifyerConfig): MockifyerInstance {
1719
1856
  });
1720
1857
  }
1721
1858
 
1722
- const responseBody = typeof response.data === 'string' ? response.data : JSON.stringify(response.data);
1723
-
1724
- return new Response(responseBody, {
1859
+ return new Response(bodyInitForFetchResponse(response.status, response.data), {
1725
1860
  status: response.status,
1726
1861
  statusText: response.statusText || '',
1727
1862
  headers: responseHeaders
@@ -1732,13 +1867,10 @@ export function setupMockifyer(config: MockifyerConfig): MockifyerInstance {
1732
1867
  Object.entries(error.response.headers || {}).forEach(([key, value]) => {
1733
1868
  responseHeaders.set(key, String(value));
1734
1869
  });
1735
-
1736
- const errorBody = typeof error.response.data === 'string'
1737
- ? error.response.data
1738
- : JSON.stringify(error.response.data);
1739
-
1740
- return new Response(errorBody, {
1741
- status: error.response.status,
1870
+
1871
+ const errorStatus = error.response.status;
1872
+ return new Response(bodyInitForFetchResponse(errorStatus, error.response.data), {
1873
+ status: errorStatus,
1742
1874
  statusText: error.response.statusText || '',
1743
1875
  headers: responseHeaders
1744
1876
  });