diff --git a/src/client.ts b/src/client.ts index eb10bf9..e60d273 100644 --- a/src/client.ts +++ b/src/client.ts @@ -57,6 +57,16 @@ export class Client { options?: object, metadata?: Metadata ) { + if (!url) { + throw new Error('Error: url is required for server reflection'); + } + + if (!credentials) { + throw new Error( + 'Error: credentials parameter is required for server reflection' + ); + } + this.url = url; this.credentials = credentials; this.clientOptions = options; @@ -114,27 +124,27 @@ export class Client { supportedReflectionAPIVersions[ version as keyof typeof supportedReflectionAPIVersions ]; - const { - service: servicePromise, - client: clientPromise, - } = protocolConfig; - - const [protocolService, protocolClient] = await Promise.all([ - servicePromise, - clientPromise, - ]); - - const grpcClientForProtocol = new protocolService.ServerReflectionClient( - this.url, - this.credentials, - this.clientOptions - ); - const request = new protocolClient.ServerReflectionRequest(); + try { + const {service: servicePromise, client: clientPromise} = + protocolConfig; + + const [protocolService, protocolClient] = await Promise.all([ + servicePromise, + clientPromise, + ]); + + const grpcClientForProtocol = + new protocolService.ServerReflectionClient( + this.url, + this.credentials, + this.clientOptions + ); - request.setListServices('*'); + const request = new protocolClient.ServerReflectionRequest(); + + request.setListServices('*'); - try { const [reflectionResponse] = await this.sendReflectionRequest( request, grpcClientForProtocol @@ -174,7 +184,7 @@ export class Client { }); const resultWithServiceError = evaluationResults.find(res => { - // Something is actually wrong with the gRPC service + // Something is actually wrong with the gRPC service or client return res.error && res.error.code !== GrpcStatus.UNIMPLEMENTED; });