Commit 9cc37d26 authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

fixed error where http.statuscode was never checked

parent bb784ec5
......@@ -26,19 +26,16 @@ type mashup interface {
func (c *tempCountry) unmarshal(resp *http.Response) error {
err := json.NewDecoder(resp.Body).Decode(&c)
defer resp.Body.Close()
return err
}
func (r *response) unmarshal(resp *http.Response) error {
err := json.NewDecoder(resp.Body).Decode(&r)
defer resp.Body.Close()
return err
}
func (s *Specie) unmarshal(resp *http.Response) error {
err := json.NewDecoder(resp.Body).Decode(&s)
defer resp.Body.Close()
return err
}
......@@ -51,17 +48,20 @@ func getBody(url string, m mashup) error {
return err
}
// decodes the http response & closes the body
err = unfold(m, resp)
if err != nil {
return err
}
// ensure that response body is closed
defer resp.Body.Close()
// sends appropriate error
// sends appropriate error if status code is not 200 OK
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("bad status code: %d", resp.StatusCode)
}
// decodes the http response
err = unfold(m, resp)
if err != nil {
return err
}
// all went well
return nil
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment