influxdata / influxdb1-client

The old clientv2 for InfluxDB 1.x
MIT License
191 stars 112 forks source link

(r *ChunkedResponse) NextResponse() removes information about underlying error #23

Closed gerardolima closed 1 year ago

gerardolima commented 5 years ago

(r *ChunkedResponse) NextResponse() is currently defined by the following code on client.go. The error checking forgets about the original error and then creates another one from the buffer. For timeout errors, this causes that the error message is empty ("").

// NextResponse reads the next line of the stream and returns a response.
func (r *ChunkedResponse) NextResponse() (*Response, error) {
    var response Response
    if err := r.dec.Decode(&response); err != nil {
        if err == io.EOF {
            return nil, err
        }
        // A decoding error happened. This probably means the server crashed
        // and sent a last-ditch error message to us. Ensure we have read the
        // entirety of the connection to get any remaining error text.
        io.Copy(ioutil.Discard, r.duplex)
        return nil, errors.New(strings.TrimSpace(r.buf.String()))
    }

    r.buf.Reset()
    return &response, nil
}