Skip to content

Commit e7a753e

Browse files
committed
Ensure error is thrown if no compatible reflection API is found
1 parent dd268d7 commit e7a753e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/client.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class Client {
9595
});
9696
}
9797

98-
private async evaluateServerReflectionProtocol() {
98+
private async evaluateSupportedServerReflectionProtocol() {
9999
const evaluationPromises = [];
100100

101101
// Check version compatibility and initialize gRPC client based on that
@@ -169,17 +169,20 @@ export class Client {
169169
.sort((res1, res2) => res2.priority - res1.priority);
170170

171171
if (!successfulReflectionByPriority) {
172-
// TODO: Do we error out here or just return empty results?
173-
const noCompatibleProtocolRrror = new Error(
174-
'No compatible reflection API found on server.'
175-
);
172+
const reflectionNotImplementedError = evaluationResults.find(res => {
173+
return res.error && res.error.code === GrpcStatus.UNIMPLEMENTED;
174+
});
176175

177176
const resultWithServiceError = evaluationResults.find(res => {
178177
// Something is actually wrong with the gRPC service
179178
return res.error && res.error.code !== GrpcStatus.UNIMPLEMENTED;
180179
});
181180

182-
throw resultWithServiceError?.error || noCompatibleProtocolRrror;
181+
throw (
182+
resultWithServiceError?.error ||
183+
reflectionNotImplementedError?.error ||
184+
new Error('No compatible reflection API found.')
185+
);
183186
}
184187

185188
// Set grpc client and other properties based on highest priority successful version
@@ -189,7 +192,7 @@ export class Client {
189192
private async initializeReflectionClient() {
190193
if (this.grpcClient || this.compatibleProtocol) return;
191194

192-
await this.evaluateServerReflectionProtocol();
195+
await this.evaluateSupportedServerReflectionProtocol();
193196
}
194197

195198
async listServices(): Promise<string[]> {

0 commit comments

Comments
 (0)