Commit 32a277faa69bf209d3583f74687bae4f8993eccf

Authored by Marko Tikvić
1 parent 765a887d9c
Exists in master

handle unsuccessful status codes

Showing 1 changed file with 8 additions and 0 deletions   Show diff stats
... ... @@ -46,6 +46,10 @@ func GetJSON(url string, v interface{}, params url.Values, headers http.Header)
46 46 defer resp.Body.Close()
47 47 status = resp.StatusCode
48 48  
  49 + if status != http.StatusOK {
  50 + return status, err
  51 + }
  52 +
49 53 if err = DecodeJSON(resp.Body, v); err == io.EOF {
50 54 err = nil
51 55 }
... ... @@ -87,6 +91,10 @@ func PostJSON(url string, v, r interface{}, params url.Values, headers http.Head
87 91 status = resp.StatusCode
88 92 defer resp.Body.Close()
89 93  
  94 + if status != http.StatusOK && status != http.StatusCreated {
  95 + return status, err
  96 + }
  97 +
90 98 if err = DecodeJSON(resp.Body, v); err == io.EOF {
91 99 err = nil
92 100 }
... ...