Make client return error on JSON decoding error
If the response is not valid JSON, the request simply returns an
empty body. If the user is expecting the result to be JSON and its
not, we should signal that an error has occured.
This patch also includes fixes to tests that fail due to the
error that bubbles up.
diff --git a/provider_client.go b/provider_client.go
index 4eeec59..d920913 100644
--- a/provider_client.go
+++ b/provider_client.go
@@ -227,7 +227,9 @@
// Parse the response body as JSON, if requested to do so.
if options.JSONResponse != nil {
defer resp.Body.Close()
- json.NewDecoder(resp.Body).Decode(options.JSONResponse)
+ if err := json.NewDecoder(resp.Body).Decode(options.JSONResponse); err != nil {
+ return nil, err
+ }
}
return resp, nil