浏览代码

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

Ramon Carvalho Maciel 6 年之前
父节点
当前提交
d791a6211d
共有 1 个文件被更改,包括 4 次插入3 次删除
  1. 4 3
      pkg/tsdb/influxdb/influxdb.go

+ 4 - 3
pkg/tsdb/influxdb/influxdb.go

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