diff --git a/conn.go b/conn.go index ca6d772..3cec0ad 100644 --- a/conn.go +++ b/conn.go @@ -14,6 +14,7 @@ import ( "net/http" "net/url" "os" + "strings" "sync/atomic" "time" @@ -278,10 +279,10 @@ func (c *conn) doRequest(ctx context.Context, req *http.Request) (io.ReadCloser, return nil, fmt.Errorf("doRequest: transport failed to send a request to ClickHouse: %w", err) } - if err = callCtxTransportCallback(ctx, req, resp); err != nil { - c.cancel = nil - return nil, fmt.Errorf("doRequest: transport callback: %w", err) - } + if err = callCtxTransportCallback(ctx, req, resp); err != nil { + c.cancel = nil + return nil, fmt.Errorf("doRequest: transport callback: %w", err) + } if resp.StatusCode != 200 { msg, err := readResponse(resp) @@ -293,6 +294,9 @@ func (c *conn) doRequest(ctx context.Context, req *http.Request) (io.ReadCloser, // response return nil, newError(string(msg)) } + if errHeader, ok := resp.Header[http.CanonicalHeaderKey("X-ClickHouse-Exception-Code")]; ok { + return nil, newError(strings.Join(errHeader, ", ")) + } return resp.Body, nil }