@@ -19,13 +19,13 @@ export class ReachabilityError extends Error {
1919 */
2020export interface ReachabilityBackend {
2121 /**
22- * Performs a test HTTP request to the specified `registry `. Resolves to the status code,
22+ * Performs a test HTTP request to the specified `url `. Resolves to the status code,
2323 * if a successful status code was obtained. Otherwise throws
2424 *
25- * @param registry The registry to try and reach.
25+ * @param url The URL of the registry to try and reach.
2626 * @returns The successful status code (in the `<400` range).
2727 */
28- checkConnection : ( registry : Registry ) => Promise < number > ;
28+ checkConnection : ( url : URL ) => Promise < number > ;
2929}
3030
3131class NetworkReachabilityBackend implements ReachabilityBackend {
@@ -35,10 +35,10 @@ class NetworkReachabilityBackend implements ReachabilityBackend {
3535 this . agent = new HttpsProxyAgent ( `http://${ proxy . host } :${ proxy . port } ` ) ;
3636 }
3737
38- public async checkConnection ( registry : Registry ) : Promise < number > {
38+ public async checkConnection ( url : URL ) : Promise < number > {
3939 return new Promise ( ( resolve , reject ) => {
4040 const req = https . request (
41- getAddressString ( registry ) ,
41+ url ,
4242 {
4343 agent : this . agent ,
4444 method : "HEAD" ,
@@ -93,22 +93,27 @@ export async function checkConnections(
9393
9494 for ( const registry of proxy . registries ) {
9595 const address = getAddressString ( registry ) ;
96- try {
97- logger . debug ( `Testing connection to ${ address } ...` ) ;
98- const statusCode = await backend . checkConnection ( registry ) ;
96+ const url = URL . parse ( address ) ;
9997
98+ if ( url === null ) {
10099 logger . info (
101- `Successfully tested connection to ${ address } ( ${ statusCode } ) ` ,
100+ `Skipping check for ${ address } since it is not a valid URL. ` ,
102101 ) ;
102+ continue ;
103+ }
104+
105+ try {
106+ logger . debug ( `Testing connection to ${ url } ...` ) ;
107+ const statusCode = await backend . checkConnection ( url ) ;
108+
109+ logger . info ( `Successfully tested connection to ${ url } (${ statusCode } )` ) ;
103110 result . add ( registry ) ;
104111 } catch ( e ) {
105112 if ( e instanceof ReachabilityError && e . statusCode !== undefined ) {
106- logger . error (
107- `Connection test to ${ address } failed. (${ e . statusCode } )` ,
108- ) ;
113+ logger . error ( `Connection test to ${ url } failed. (${ e . statusCode } )` ) ;
109114 } else {
110115 logger . error (
111- `Connection test to ${ address } failed: ${ getErrorMessage ( e ) } ` ,
116+ `Connection test to ${ url } failed: ${ getErrorMessage ( e ) } ` ,
112117 ) ;
113118 }
114119 }
0 commit comments