From 26062af9eedf03e2289ab5450f82b93380f49e3e Mon Sep 17 00:00:00 2001 From: Cheskel Twersky Date: Tue, 5 Nov 2024 14:55:15 +0200 Subject: [PATCH 1/3] fix: check the X-ClickHouse-Exception-Code for err code, fixes: #332 --- packages/client-common/src/utils/connection.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/client-common/src/utils/connection.ts b/packages/client-common/src/utils/connection.ts index 62e65ea..b505cef 100644 --- a/packages/client-common/src/utils/connection.ts +++ b/packages/client-common/src/utils/connection.ts @@ -33,6 +33,14 @@ export function withHttpSettings( } } -export function isSuccessfulResponse(statusCode?: number): boolean { - return Boolean(statusCode && 200 <= statusCode && statusCode < 300) +export function isSuccessfulResponse( + statusCode?: number, + headers: Record = {}, +): boolean { + return Boolean( + statusCode && + 200 <= statusCode && + statusCode < 300 && + !headers['X-ClickHouse-Exception-Code'], + ) } From 07273544c541e950749cbac5f3683ee5e389c50f Mon Sep 17 00:00:00 2001 From: Cheskel Twersky Date: Tue, 5 Nov 2024 15:13:07 +0200 Subject: [PATCH 2/3] its lowercase --- packages/client-common/src/utils/connection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client-common/src/utils/connection.ts b/packages/client-common/src/utils/connection.ts index b505cef..1485b28 100644 --- a/packages/client-common/src/utils/connection.ts +++ b/packages/client-common/src/utils/connection.ts @@ -41,6 +41,6 @@ export function isSuccessfulResponse( statusCode && 200 <= statusCode && statusCode < 300 && - !headers['X-ClickHouse-Exception-Code'], + !headers['x-clickhouse-exception-code'], ) } From f673b4524e09e2b437c6c9f636f121589462e377 Mon Sep 17 00:00:00 2001 From: Cheskel Twersky Date: Tue, 5 Nov 2024 16:05:39 +0200 Subject: [PATCH 3/3] pass headers --- packages/client-common/src/utils/connection.ts | 2 +- packages/client-node/src/connection/node_base_connection.ts | 5 ++++- packages/client-web/src/connection/web_connection.ts | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/client-common/src/utils/connection.ts b/packages/client-common/src/utils/connection.ts index 1485b28..381f46f 100644 --- a/packages/client-common/src/utils/connection.ts +++ b/packages/client-common/src/utils/connection.ts @@ -35,7 +35,7 @@ export function withHttpSettings( export function isSuccessfulResponse( statusCode?: number, - headers: Record = {}, + headers: any = {}, ): boolean { return Boolean( statusCode && diff --git a/packages/client-node/src/connection/node_base_connection.ts b/packages/client-node/src/connection/node_base_connection.ts index 5c4b1ec..4b75768 100644 --- a/packages/client-node/src/connection/node_base_connection.ts +++ b/packages/client-node/src/connection/node_base_connection.ts @@ -460,7 +460,10 @@ export abstract class NodeBaseConnection const tryDecompressResponseStream = params.try_decompress_response_stream ?? true // even if the stream decompression is disabled, we have to decompress it in case of an error - const isFailedResponse = !isSuccessfulResponse(_response.statusCode) + const isFailedResponse = !isSuccessfulResponse( + _response.statusCode, + _response.headers, + ) if (tryDecompressResponseStream || isFailedResponse) { const decompressionResult = decompressResponse(_response) if (isDecompressionError(decompressionResult)) { diff --git a/packages/client-web/src/connection/web_connection.ts b/packages/client-web/src/connection/web_connection.ts index 72c69ea..f391c94 100644 --- a/packages/client-web/src/connection/web_connection.ts +++ b/packages/client-web/src/connection/web_connection.ts @@ -191,7 +191,7 @@ export class WebConnection implements Connection { signal: abortController.signal, }) clearTimeout(timeout) - if (isSuccessfulResponse(response.status)) { + if (isSuccessfulResponse(response.status, response.headers)) { return response } else { return Promise.reject(