mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Handle errors from the grafana api by displaying the error message (#1015)
This commit is contained in:
parent
bd01083ad6
commit
f58e244cf6
@ -3,6 +3,7 @@ package grafana
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
@ -91,6 +92,17 @@ func (client *Client) Alerts() ([]Alert, error) {
|
|||||||
}
|
}
|
||||||
defer func() { _ = res.Body.Close() }()
|
defer func() { _ = res.Body.Close() }()
|
||||||
|
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
msg := struct {
|
||||||
|
Msg string `json:"message"`
|
||||||
|
}{}
|
||||||
|
err = utils.ParseJSON(&msg, res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return nil, errors.New(msg.Msg)
|
||||||
|
}
|
||||||
|
|
||||||
var out []Alert
|
var out []Alert
|
||||||
err = utils.ParseJSON(&out, res.Body)
|
err = utils.ParseJSON(&out, res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user