Improve error messages through proxy

Previously, the proxy would only report the error code it received from
an InfluxDB instance. This also passes the error message returned by
InfluxDB through, so it appears in the Chronograf server logs as well as
in the response returned to the frontend by the proxy (making it visible
by inspecting the request in the network tab).
pull/672/head
Tim Raymond 2016-12-13 11:59:26 -05:00
parent 06cdd47d47
commit c1effd7f47
1 changed files with 4 additions and 3 deletions

View File

@ -70,14 +70,15 @@ func (c *Client) query(u *url.URL, q chronograf.Query) (chronograf.Response, err
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("received status code %d from server", resp.StatusCode)
}
var response Response
dec := json.NewDecoder(resp.Body)
decErr := dec.Decode(&response)
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("received status code %d from server: err: %s", resp.StatusCode, response.Err)
}
// ignore this error if we got an invalid status code
if decErr != nil && decErr.Error() == "EOF" && resp.StatusCode != http.StatusOK {
decErr = nil