Skip to content

Commit 5db1b84

Browse files
committed
Set error code in grpc response
1 parent 104d33d commit 5db1b84

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

clickhouse-grpc-client/src/main/java/com/clickhouse/client/grpc/ClickHouseGrpcClient.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ protected static Compression getResultCompression(ClickHouseConfig config) {
5757
CompressionAlgorithm algorithm = CompressionAlgorithm.DEFLATE;
5858
CompressionLevel level = CompressionLevel.COMPRESSION_MEDIUM;
5959
switch (config.getDecompressAlgorithmForClientRequest()) {
60-
case NONE:
61-
algorithm = CompressionAlgorithm.NO_COMPRESSION;
62-
break;
63-
case DEFLATE:
64-
break;
65-
case GZIP:
66-
algorithm = CompressionAlgorithm.GZIP;
67-
break;
68-
// case STREAM_GZIP:
69-
default:
70-
log.warn("Unsupported algorithm [%s], change to [%s]", config.getDecompressAlgorithmForClientRequest(),
71-
algorithm);
72-
break;
60+
case NONE:
61+
algorithm = CompressionAlgorithm.NO_COMPRESSION;
62+
break;
63+
case DEFLATE:
64+
break;
65+
case GZIP:
66+
algorithm = CompressionAlgorithm.GZIP;
67+
break;
68+
// case STREAM_GZIP:
69+
default:
70+
log.warn("Unsupported algorithm [%s], change to [%s]", config.getDecompressAlgorithmForClientRequest(),
71+
algorithm);
72+
break;
7373
}
7474

7575
int l = config.getDecompressLevelForClientRequest();
@@ -269,7 +269,8 @@ protected CompletableFuture<ClickHouseResponse> executeSync(ClickHouseRequest<?>
269269
sealedRequest.getSettings(), result);
270270

271271
return result.hasException()
272-
? failedResponse(ClickHouseException.of(result.getException().getDisplayText(), server))
272+
? failedResponse(new ClickHouseException(result.getException().getCode(),
273+
result.getException().getDisplayText(), server))
273274
: CompletableFuture.completedFuture(response);
274275
} catch (IOException e) {
275276
throw new CompletionException(ClickHouseException.of(e, server));

clickhouse-grpc-client/src/test/java/com/clickhouse/client/grpc/ClickHouseGrpcClientTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,19 @@ public void testReadWriteDateTimeTypes() throws Exception {
277277
}
278278
}
279279

280+
@Test(groups = "integration")
281+
public void testDropNonExistDb() throws Exception {
282+
ClickHouseNode server = getServer(ClickHouseProtocol.GRPC);
283+
284+
try {
285+
ClickHouseClient.send(server, "drop database non_exist_db").get();
286+
Assert.fail("Exception is excepted");
287+
} catch (ExecutionException e) {
288+
ClickHouseException ce = (ClickHouseException) e.getCause();
289+
Assert.assertEquals(ce.getErrorCode(), 81);
290+
}
291+
}
292+
280293
@Test(groups = "integration")
281294
public void testReadWriteDomains() throws Exception {
282295
ClickHouseNode server = getServer(ClickHouseProtocol.GRPC);

0 commit comments

Comments
 (0)