1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Fix for potential runtime panic (#1046)

Switch error checking around, so we don't check the StatusCode before
handling client errors.
This commit is contained in:
Fredrik Steen 2021-01-20 18:03:27 +01:00 committed by GitHub
parent 7c3d476def
commit ddfc439c41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -165,13 +165,14 @@ func (widget *Widget) getExistingChecks() ([]Checks, error) {
req.Header.Set("X-Api-Key", widget.settings.apiKey)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf(resp.Status)
}
if err != nil {
return nil, err
}
defer func() { _ = resp.Body.Close() }()
var health Health