@@ -5,7 +5,7 @@ import { HttpsProxyAgent } from "https-proxy-agent";
55import { Logger } from "../logging" ;
66import { getErrorMessage } from "../util" ;
77
8- import { ProxyInfo , Registry } from "./types" ;
8+ import { getAddressString , ProxyInfo , Registry , ValidRegistry } from "./types" ;
99
1010export class ReachabilityError extends Error {
1111 constructor (
@@ -34,7 +34,7 @@ export interface ReachabilityBackend {
3434 * @param registry The registry to try and reach.
3535 * @returns The successful status code (in the `<400` range).
3636 */
37- checkConnection : ( registry : Registry ) => Promise < number > ;
37+ checkConnection : ( registry : ValidRegistry ) => Promise < number > ;
3838}
3939
4040class NetworkReachabilityBackend implements ReachabilityBackend {
@@ -47,10 +47,10 @@ class NetworkReachabilityBackend implements ReachabilityBackend {
4747 this . agent = new HttpsProxyAgent ( `http://${ proxy . host } :${ proxy . port } ` ) ;
4848 }
4949
50- public async checkConnection ( registry : Registry ) : Promise < number > {
50+ public async checkConnection ( registry : ValidRegistry ) : Promise < number > {
5151 return new Promise ( ( resolve , reject ) => {
5252 const req = https . request (
53- registry . url as string ,
53+ getAddressString ( registry ) ,
5454 { agent : this . agent , method : "HEAD" , ca : this . proxy . cert } ,
5555 ( res ) => {
5656 res . destroy ( ) ;
@@ -83,8 +83,8 @@ export async function checkConnections(
8383 logger : Logger ,
8484 proxy : ProxyInfo ,
8585 backend ?: ReachabilityBackend ,
86- ) : Promise < Set < Registry > > {
87- const result : Set < Registry > = new Set ( ) ;
86+ ) : Promise < Set < ValidRegistry > > {
87+ const result : Set < ValidRegistry > = new Set ( ) ;
8888
8989 // Don't do anything if there are no registries.
9090 if ( proxy . registries . length === 0 ) return result ;
@@ -96,22 +96,23 @@ export async function checkConnections(
9696 }
9797
9898 for ( const registry of proxy . registries ) {
99+ const address = getAddressString ( registry ) ;
99100 try {
100- logger . debug ( `Testing connection to ${ registry . url } ...` ) ;
101+ logger . debug ( `Testing connection to ${ address } ...` ) ;
101102 const statusCode = await backend . checkConnection ( registry ) ;
102103
103104 logger . info (
104- `Successfully tested connection to ${ registry . url } (${ statusCode } )` ,
105+ `Successfully tested connection to ${ address } (${ statusCode } )` ,
105106 ) ;
106107 result . add ( registry ) ;
107108 } catch ( e ) {
108109 if ( e instanceof ReachabilityError && e . statusCode !== undefined ) {
109110 logger . error (
110- `Connection test to ${ registry . url } failed. (${ e . statusCode } )` ,
111+ `Connection test to ${ address } failed. (${ e . statusCode } )` ,
111112 ) ;
112113 } else {
113114 logger . error (
114- `Connection test to ${ registry . url } failed: ${ getErrorMessage ( e ) } ` ,
115+ `Connection test to ${ address } failed: ${ getErrorMessage ( e ) } ` ,
115116 ) ;
116117 }
117118 }
0 commit comments