@sgedda/mockifyer-fetch 1.8.43 → 1.8.44

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.
package/dist/index.js CHANGED
@@ -91,6 +91,16 @@ class MockifyerClass {
91
91
  const parentRequestId = config.__mockifyer_parentRequestId;
92
92
  return parentRequestId ? { requestId, parentRequestId } : { requestId };
93
93
  }
94
+ /** Attach dashboard lookup id onto thrown fetch/client errors. */
95
+ throwWithMockifyerRequestId(error) {
96
+ const err = error;
97
+ const hopRequestId = err?.config?.__mockifyer_requestId;
98
+ const requestId = (0, mockifyer_core_1.resolveMockifyerRequestIdForError)({
99
+ hopRequestId,
100
+ responseHeaders: err?.response?.headers,
101
+ });
102
+ throw (0, mockifyer_core_1.attachMockifyerRequestIdToError)(error, requestId);
103
+ }
94
104
  /**
95
105
  * Serve stored mock body with optional `$pool` resolution from the local fixture pool.
96
106
  * Always passes `loadPoolResponse` — including React Native where Node `fs`/`path` are
@@ -781,7 +791,7 @@ class MockifyerClass {
781
791
  responseBody: error.response?.data,
782
792
  }, this.readRequestCorrelation(error.config));
783
793
  }
784
- throw error;
794
+ this.throwWithMockifyerRequestId(error);
785
795
  });
786
796
  }
787
797
  /**
@@ -1376,7 +1386,11 @@ function setupMockifyer(config) {
1376
1386
  headers: responseHeaders
1377
1387
  });
1378
1388
  }
1379
- throw error;
1389
+ throw (0, mockifyer_core_1.attachMockifyerRequestIdToError)(error, (0, mockifyer_core_1.resolveMockifyerRequestIdForError)({
1390
+ hopRequestId: error?.config
1391
+ ?.__mockifyer_requestId,
1392
+ responseHeaders: error?.response?.headers,
1393
+ }));
1380
1394
  }
1381
1395
  };
1382
1396
  mockifyer_core_2.logger.info('[Mockifyer] ✅ Patched global fetch (useGlobalFetch: true)');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sgedda/mockifyer-fetch",
3
- "version": "1.8.43",
3
+ "version": "1.8.44",
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.25"
52
+ "@sgedda/mockifyer-core": "^1.10.27"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^20.11.24",
package/src/index.ts CHANGED
@@ -75,6 +75,8 @@ import {
75
75
  getInlineTraceEnvelopeBusinessBody,
76
76
  resolveRecordResponses,
77
77
  applyOutboundRequestCorrelation,
78
+ attachMockifyerRequestIdToError,
79
+ resolveMockifyerRequestIdForError,
78
80
  type RequestCorrelationContext,
79
81
  installNodeInboundRequestCorrelationCapture,
80
82
  } from '@sgedda/mockifyer-core';
@@ -184,6 +186,17 @@ class MockifyerClass {
184
186
  return parentRequestId ? { requestId, parentRequestId } : { requestId };
185
187
  }
186
188
 
189
+ /** Attach dashboard lookup id onto thrown fetch/client errors. */
190
+ private throwWithMockifyerRequestId(error: unknown): never {
191
+ const err = error as { config?: unknown; response?: { headers?: unknown } };
192
+ const hopRequestId = (err?.config as { __mockifyer_requestId?: string } | undefined)?.__mockifyer_requestId;
193
+ const requestId = resolveMockifyerRequestIdForError({
194
+ hopRequestId,
195
+ responseHeaders: err?.response?.headers,
196
+ });
197
+ throw attachMockifyerRequestIdToError(error, requestId);
198
+ }
199
+
187
200
  /**
188
201
  * Serve stored mock body with optional `$pool` resolution from the local fixture pool.
189
202
  * Always passes `loadPoolResponse` — including React Native where Node `fs`/`path` are
@@ -1013,7 +1026,7 @@ class MockifyerClass {
1013
1026
  this.readRequestCorrelation(error.config)
1014
1027
  );
1015
1028
  }
1016
- throw error;
1029
+ this.throwWithMockifyerRequestId(error);
1017
1030
  }
1018
1031
  );
1019
1032
  }
@@ -1715,7 +1728,14 @@ export function setupMockifyer(config: MockifyerConfig): MockifyerInstance {
1715
1728
  headers: responseHeaders
1716
1729
  });
1717
1730
  }
1718
- throw error;
1731
+ throw attachMockifyerRequestIdToError(
1732
+ error,
1733
+ resolveMockifyerRequestIdForError({
1734
+ hopRequestId: (error as { config?: { __mockifyer_requestId?: string } })?.config
1735
+ ?.__mockifyer_requestId,
1736
+ responseHeaders: (error as { response?: { headers?: unknown } })?.response?.headers,
1737
+ })
1738
+ );
1719
1739
  }
1720
1740
  } as typeof fetch;
1721
1741