Skip to content

Commit f75d349

Browse files
committed
fix: FetchError from node-fetch
1 parent c87f409 commit f75d349

1 file changed

Lines changed: 3 additions & 20 deletions

File tree

packages/network-controller/src/create-network-client-tests/classify-retry-reason.test.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,13 @@
11
import { HttpError } from '@metamask/controller-utils';
2+
import { FetchError } from 'node-fetch';
23

34
import { classifyRetryReason } from '../create-network-client';
45

5-
/**
6-
* Creates a FetchError-like object matching the pattern that isConnectionError
7-
* expects from node-fetch.
8-
*
9-
* @param message - The error message.
10-
* @returns A FetchError-like object.
11-
*/
12-
function createFetchError(message: string): Error {
13-
const error = new Error(message);
14-
Object.defineProperty(error, 'constructor', {
15-
value: { name: 'FetchError' },
16-
});
17-
Object.defineProperty(error.constructor, 'name', {
18-
value: 'FetchError',
19-
writable: false,
20-
});
21-
return error;
22-
}
23-
246
describe('classifyRetryReason', () => {
257
it('returns "connection_failed" for FetchError connection failures', () => {
26-
const error = createFetchError(
8+
const error = new FetchError(
279
'request to https://example.com failed, reason: connect ECONNREFUSED',
10+
'system',
2811
);
2912
expect(classifyRetryReason(error)).toBe('connection_failed');
3013
});

0 commit comments

Comments
 (0)