diff --git a/packages/client-common/src/utils/connection.ts b/packages/client-common/src/utils/connection.ts index 62e65ea..381f46f 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: any = {}, +): boolean { + return Boolean( + statusCode && + 200 <= statusCode && + statusCode < 300 && + !headers['x-clickhouse-exception-code'], + ) } 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(