mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
fix(InfluxDB): Reads body and close request body even for error status codes (#16207)
This commit is contained in:
parent
941b770c46
commit
d791a6211d
@ -4,16 +4,16 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"golang.org/x/net/context/ctxhttp"
|
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/log"
|
"github.com/grafana/grafana/pkg/log"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/tsdb"
|
"github.com/grafana/grafana/pkg/tsdb"
|
||||||
|
"golang.org/x/net/context/ctxhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InfluxDBExecutor struct {
|
type InfluxDBExecutor struct {
|
||||||
@ -71,13 +71,14 @@ func (e *InfluxDBExecutor) Query(ctx context.Context, dsInfo *models.DataSource,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode/100 != 2 {
|
if resp.StatusCode/100 != 2 {
|
||||||
|
ioutil.ReadAll(resp.Body)
|
||||||
return nil, fmt.Errorf("Influxdb returned statuscode invalid status code: %v", resp.Status)
|
return nil, fmt.Errorf("Influxdb returned statuscode invalid status code: %v", resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
var response Response
|
var response Response
|
||||||
dec := json.NewDecoder(resp.Body)
|
dec := json.NewDecoder(resp.Body)
|
||||||
defer resp.Body.Close()
|
|
||||||
dec.UseNumber()
|
dec.UseNumber()
|
||||||
err = dec.Decode(&response)
|
err = dec.Decode(&response)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user