Merge pull request #484 from pratikmallya/fix_gc_client

[rfr]Make client return error on JSON decoding error
diff --git a/openstack/compute/v2/extensions/secgroups/fixtures.go b/openstack/compute/v2/extensions/secgroups/fixtures.go
index 1c6ba39..8c42e48 100644
--- a/openstack/compute/v2/extensions/secgroups/fixtures.go
+++ b/openstack/compute/v2/extensions/secgroups/fixtures.go
@@ -242,6 +242,7 @@
 
 		w.Header().Add("Content-Type", "application/json")
 		w.WriteHeader(http.StatusAccepted)
+		fmt.Fprintf(w, `{}`)
 	})
 }
 
@@ -261,5 +262,6 @@
 
 		w.Header().Add("Content-Type", "application/json")
 		w.WriteHeader(http.StatusAccepted)
+		fmt.Fprintf(w, `{}`)
 	})
 }
diff --git a/openstack/compute/v2/servers/requests.go b/openstack/compute/v2/servers/requests.go
index 63ad24b..f9839d9 100644
--- a/openstack/compute/v2/servers/requests.go
+++ b/openstack/compute/v2/servers/requests.go
@@ -754,9 +754,7 @@
 // DeleteMetadatum will delete the key-value pair with the given key for the given server ID.
 func DeleteMetadatum(client *gophercloud.ServiceClient, id, key string) DeleteMetadatumResult {
 	var res DeleteMetadatumResult
-	_, res.Err = client.Delete(metadatumURL(client, id, key), &gophercloud.RequestOpts{
-		JSONResponse: &res.Body,
-	})
+	_, res.Err = client.Delete(metadatumURL(client, id, key), nil)
 	return res
 }
 
diff --git a/openstack/networking/v2/extensions/fwaas/firewalls/requests_test.go b/openstack/networking/v2/extensions/fwaas/firewalls/requests_test.go
index f24e283..19d32c5 100644
--- a/openstack/networking/v2/extensions/fwaas/firewalls/requests_test.go
+++ b/openstack/networking/v2/extensions/fwaas/firewalls/requests_test.go
@@ -212,9 +212,9 @@
         "name": "fw",
         "admin_state_up": false,
         "tenant_id": "b4eedccc6fb74fa8a7ad6b08382b852b",
-        "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c"
+        "firewall_policy_id": "19ab8c87-4a32-4e6a-a74e-b77fffb89a0c",
         "id": "ea5b5315-64f6-4ea3-8e58-981cc37c6576",
-        "description": "OpenStack firewall",
+        "description": "OpenStack firewall"
     }
 }
     `)
diff --git a/openstack/networking/v2/extensions/lbaas/pools/requests_test.go b/openstack/networking/v2/extensions/lbaas/pools/requests_test.go
index 6da29a6..3b5c7c7 100644
--- a/openstack/networking/v2/extensions/lbaas/pools/requests_test.go
+++ b/openstack/networking/v2/extensions/lbaas/pools/requests_test.go
@@ -296,6 +296,7 @@
 
 		w.Header().Add("Content-Type", "application/json")
 		w.WriteHeader(http.StatusCreated)
+		fmt.Fprintf(w, `{}`)
 	})
 
 	_, err := AssociateMonitor(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "b624decf-d5d3-4c66-9a3d-f047e7786181").Extract()
diff --git a/openstack/networking/v2/networks/requests_test.go b/openstack/networking/v2/networks/requests_test.go
index a263b7b..81eb79c 100644
--- a/openstack/networking/v2/networks/requests_test.go
+++ b/openstack/networking/v2/networks/requests_test.go
@@ -204,6 +204,7 @@
 		`)
 
 		w.WriteHeader(http.StatusCreated)
+		fmt.Fprintf(w, `{}`)
 	})
 
 	iTrue := true
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
diff --git a/rackspace/lb/v1/sessions/fixtures.go b/rackspace/lb/v1/sessions/fixtures.go
index 9596819..077ef04 100644
--- a/rackspace/lb/v1/sessions/fixtures.go
+++ b/rackspace/lb/v1/sessions/fixtures.go
@@ -46,6 +46,7 @@
     `)
 
 		w.WriteHeader(http.StatusAccepted)
+		fmt.Fprintf(w, `{}`)
 	})
 }
 
diff --git a/rackspace/lb/v1/ssl/fixtures.go b/rackspace/lb/v1/ssl/fixtures.go
index 1d40100..5a52962 100644
--- a/rackspace/lb/v1/ssl/fixtures.go
+++ b/rackspace/lb/v1/ssl/fixtures.go
@@ -63,6 +63,7 @@
     `)
 
 		w.WriteHeader(http.StatusOK)
+		fmt.Fprintf(w, `{}`)
 	})
 }
 
diff --git a/rackspace/lb/v1/throttle/fixtures.go b/rackspace/lb/v1/throttle/fixtures.go
index 40223f6..f3e49fa 100644
--- a/rackspace/lb/v1/throttle/fixtures.go
+++ b/rackspace/lb/v1/throttle/fixtures.go
@@ -49,6 +49,7 @@
     `)
 
 		w.WriteHeader(http.StatusAccepted)
+		fmt.Fprintf(w, `{}`)
 	})
 }
 
diff --git a/rackspace/networking/v2/networks/delegate_test.go b/rackspace/networking/v2/networks/delegate_test.go
index f51c732..0b3a6b1 100644
--- a/rackspace/networking/v2/networks/delegate_test.go
+++ b/rackspace/networking/v2/networks/delegate_test.go
@@ -203,8 +203,17 @@
 	}
 }
 		`)
-
 		w.WriteHeader(http.StatusCreated)
+		fmt.Fprintf(w, `
+{
+	"network": {
+			"name": "sample_network",
+			"admin_state_up": true,
+			"shared": true,
+			"tenant_id": "12345"
+	}
+}
+		`)
 	})
 
 	iTrue := true