~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/httprequest/client.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
207
207
                        return nil
208
208
                }
209
209
                defer httpResp.Body.Close()
210
 
                return UnmarshalJSONResponse(httpResp, resp)
 
210
                if err := UnmarshalJSONResponse(httpResp, resp); err != nil {
 
211
                        return errgo.Notef(err, "%s %s", httpResp.Request.Method, httpResp.Request.URL)
 
212
                }
 
213
                return nil
211
214
        }
212
215
        defer httpResp.Body.Close()
213
216
        errUnmarshaler := c.UnmarshalError
237
240
                        loc, _ := resp.Location()
238
241
                        return fmt.Errorf("unexpected redirect (status %s) from %q to %q", resp.Status, resp.Request.URL, loc)
239
242
                }
240
 
                if err := checkIsJSON(resp.Header, resp.Body); err != nil {
241
 
                        // TODO consider including some or all of the body
242
 
                        // in the error.
243
 
                        return fmt.Errorf("cannot unmarshal error response (status %s): %v", resp.Status, err)
244
 
                }
245
243
                errv := reflect.New(t)
246
244
                if err := UnmarshalJSONResponse(resp, errv.Interface()); err != nil {
247
245
                        return fmt.Errorf("cannot unmarshal error response (status %s): %v", resp.Status, err)
261
259
                return nil
262
260
        }
263
261
        if err := checkIsJSON(resp.Header, resp.Body); err != nil {
264
 
                return errgo.Notef(err, "%s %s", resp.Request.Method, resp.Request.URL)
 
262
                return errgo.Mask(err)
265
263
        }
266
264
        // Decode only a single JSON value, and then
267
265
        // discard the rest of the body so that we can
269
267
        // has put garbage on the end.
270
268
        dec := json.NewDecoder(resp.Body)
271
269
        if err := dec.Decode(x); err != nil {
272
 
                return errgo.Notef(err, "%s %s", resp.Request.Method, resp.Request.URL)
 
270
                return errgo.Mask(err)
273
271
        }
274
272
        return nil
275
273
}