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

This commit is contained in:
Ramon Carvalho Maciel 2019-03-25 13:42:27 -03:00 committed by Torkel Ödegaard
parent 941b770c46
commit d791a6211d

View File

@ -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)