Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check the X-ClickHouse-Exception-Code for err code #350

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/client-common/src/utils/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
)
}
5 changes: 4 additions & 1 deletion packages/client-node/src/connection/node_base_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-web/src/connection/web_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class WebConnection implements Connection<ReadableStream> {
signal: abortController.signal,
})
clearTimeout(timeout)
if (isSuccessfulResponse(response.status)) {
if (isSuccessfulResponse(response.status, response.headers)) {
return response
} else {
return Promise.reject(
Expand Down