Return error if status code returned from the API is not 200.
parent
948c454c25
commit
2e65239ca1
|
@ -3,6 +3,7 @@ package footballdata
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -50,12 +51,18 @@ func (c *Client) doJson(method string, path string, values url.Values) (j *json.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// Save metadata from headers
|
// Save metadata from headers
|
||||||
meta = responseMetaFromHeaders(resp.Header)
|
meta = responseMetaFromHeaders(resp.Header)
|
||||||
|
|
||||||
|
// Expect the request to be successful, otherwise throw an error
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
err = errors.New(resp.Status)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Download to buffer to allow passing back a fully prepared decoder
|
// Download to buffer to allow passing back a fully prepared decoder
|
||||||
defer resp.Body.Close()
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
io.Copy(buf, resp.Body)
|
io.Copy(buf, resp.Body)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue