Add extra checks after failed response
All checks were successful
the build was successful

This commit is contained in:
Peter Stuifzand 2018-08-19 21:34:46 +02:00
parent 407d4fb155
commit 94c86d57ff
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -3,6 +3,7 @@ package client
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
@ -83,6 +84,11 @@ func (c *Client) microsubPostRequest(action string, args map[string]string) (*ht
log.Printf("RESPONSE:\n\n%s\n\n", x) log.Printf("RESPONSE:\n\n%s\n\n", x)
} }
if res.StatusCode != 200 {
msg, _ := ioutil.ReadAll(res.Body)
return nil, fmt.Errorf("unsuccessful response: %d: %q", res.StatusCode, string(msg))
}
return res, err return res, err
} }
@ -104,7 +110,14 @@ func (c *Client) microsubPostFormRequest(action string, args map[string]string,
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.Token)) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.Token))
return client.Do(req) res, err := client.Do(req)
if res.StatusCode != 200 {
msg, _ := ioutil.ReadAll(res.Body)
return nil, fmt.Errorf("unsuccessful response: %d: %q", res.StatusCode, string(msg))
}
return res, err
} }
func (c *Client) ChannelsGetList() ([]microsub.Channel, error) { func (c *Client) ChannelsGetList() ([]microsub.Channel, error) {