File tree Expand file tree Collapse file tree
packages/network-controller/src/create-network-client-tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { HttpError } from '@metamask/controller-utils' ;
2+ import { FetchError } from 'node-fetch' ;
23
34import { 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-
246describe ( '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 } ) ;
You can’t perform that action at this time.
0 commit comments