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 (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
@ -91,6 +92,17 @@ func (client *Client) Alerts() ([]Alert, error) {
|
||||
}
|
||||
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
|
||||
err = utils.ParseJSON(&out, res.Body)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user