Commit d791a621 by Ramon Carvalho Maciel Committed by Torkel Ödegaard

fix(InfluxDB): Reads body and close request body even for error status codes (#16207)

parent 941b770c
......@@ -4,16 +4,16 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"path"
"golang.org/x/net/context/ctxhttp"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb"
"golang.org/x/net/context/ctxhttp"
)
type InfluxDBExecutor struct {
......@@ -71,13 +71,14 @@ func (e *InfluxDBExecutor) Query(ctx context.Context, dsInfo *models.DataSource,
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode/100 != 2 {
ioutil.ReadAll(resp.Body)
return nil, fmt.Errorf("Influxdb returned statuscode invalid status code: %v", resp.Status)
}
var response Response
dec := json.NewDecoder(resp.Body)
defer resp.Body.Close()
dec.UseNumber()
err = dec.Decode(&response)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment