Fix panic when influx client receives error status code
parent
2ef4a7b13d
commit
7d95840956
|
@ -59,6 +59,9 @@ func query(u *url.URL, q mrfusion.Query) (mrfusion.Response, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("received status code %d from server", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
var response Response
|
var response Response
|
||||||
dec := json.NewDecoder(resp.Body)
|
dec := json.NewDecoder(resp.Body)
|
||||||
|
@ -73,6 +76,7 @@ func query(u *url.URL, q mrfusion.Query) (mrfusion.Response, error) {
|
||||||
if decErr != nil {
|
if decErr != nil {
|
||||||
return nil, fmt.Errorf("unable to decode json: received status code %d err: %s", resp.StatusCode, decErr)
|
return nil, fmt.Errorf("unable to decode json: received status code %d err: %s", resp.StatusCode, decErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't have an error in our json response, and didn't get statusOK
|
// If we don't have an error in our json response, and didn't get statusOK
|
||||||
// then send back an error
|
// then send back an error
|
||||||
if resp.StatusCode != http.StatusOK && response.Err != "" {
|
if resp.StatusCode != http.StatusOK && response.Err != "" {
|
||||||
|
|
Loading…
Reference in New Issue