summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/handler.go
diff options
context:
space:
mode:
authorVictor Morales <victor.morales@intel.com>2019-03-22 23:31:56 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-22 23:31:56 +0000
commit8cdd50b6a06aef5cb0541e74a07b10bd4b01b589 (patch)
tree51d4392b09671e7e0f4f02862401dac4f74eef16 /src/k8splugin/api/handler.go
parent79b27040152a7c4ce3145b15d726645d90ea79d9 (diff)
parent4cd4539c71919a322180713c225fe23edf0eb12e (diff)
Merge "Use httptest instead of http in unit tests"
Diffstat (limited to 'src/k8splugin/api/handler.go')
-rw-r--r--src/k8splugin/api/handler.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/k8splugin/api/handler.go b/src/k8splugin/api/handler.go
index 32bfa594..4d6abe27 100644
--- a/src/k8splugin/api/handler.go
+++ b/src/k8splugin/api/handler.go
@@ -16,6 +16,7 @@ package api
import (
"encoding/json"
"errors"
+ "io"
"log"
"net/http"
"os"
@@ -75,13 +76,12 @@ func validateBody(body interface{}) error {
func CreateHandler(w http.ResponseWriter, r *http.Request) {
var resource CreateVnfRequest
- if r.Body == nil {
+ err := json.NewDecoder(r.Body).Decode(&resource)
+ switch {
+ case err == io.EOF:
http.Error(w, "Body empty", http.StatusBadRequest)
return
- }
-
- err := json.NewDecoder(r.Body).Decode(&resource)
- if err != nil {
+ case err != nil:
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
return
}