resolves issues where failed api calls lead to obscure errors (#7051)
This commit is contained in:
@@ -3,6 +3,8 @@ package kibana
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -250,6 +252,12 @@ func (k *Kibana) gatherJsonData(url string, v interface{}) (host string, err err
|
||||
|
||||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode != http.StatusOK {
|
||||
// ignore the err here; LimitReader returns io.EOF and we're not interested in read errors.
|
||||
body, _ := ioutil.ReadAll(io.LimitReader(response.Body, 200))
|
||||
return request.Host, fmt.Errorf("%s returned HTTP status %s: %q", url, response.Status, body)
|
||||
}
|
||||
|
||||
if err = json.NewDecoder(response.Body).Decode(v); err != nil {
|
||||
return request.Host, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user