summaryrefslogtreecommitdiffstats
path: root/src/dcm/api
diff options
context:
space:
mode:
authorRitu Sood <ritu.sood@intel.com>2020-09-25 16:36:24 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-25 16:36:24 +0000
commit8b5c4236639a46f39cbfe852590f34e64f58a85a (patch)
treea2130c27227dbeffb903888b777ece8afd8f8302 /src/dcm/api
parent6498e883dcbc005b32f86f8a57c96950c359d98e (diff)
parentc585d2b091875dbc9575a960f4f42c1f14ec3366 (diff)
Merge "Enhance error handling and HTTP codes in DCM"
Diffstat (limited to 'src/dcm/api')
-rw-r--r--src/dcm/api/clusterHandler.go10
-rw-r--r--src/dcm/api/keyValueHandler.go10
-rw-r--r--src/dcm/api/logicalCloudHandler.go20
-rw-r--r--src/dcm/api/quotaHandler.go10
-rw-r--r--src/dcm/api/userPermissionsHandler.go12
5 files changed, 57 insertions, 5 deletions
diff --git a/src/dcm/api/clusterHandler.go b/src/dcm/api/clusterHandler.go
index f4a3abdc..d0c1e62c 100644
--- a/src/dcm/api/clusterHandler.go
+++ b/src/dcm/api/clusterHandler.go
@@ -91,6 +91,10 @@ func (h clusterHandler) getHandler(w http.ResponseWriter, r *http.Request) {
} else {
ret, err = h.client.GetCluster(project, logicalCloud, name)
if err != nil {
+ if err.Error() == "Cluster Reference does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -131,12 +135,16 @@ func (h clusterHandler) updateHandler(w http.ResponseWriter, r *http.Request) {
ret, err := h.client.UpdateCluster(project, logicalCloud, name, v)
if err != nil {
+ if err.Error() == "Cluster Reference does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(),
http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(http.StatusCreated)
+ w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(ret)
if err != nil {
http.Error(w, err.Error(),
diff --git a/src/dcm/api/keyValueHandler.go b/src/dcm/api/keyValueHandler.go
index c67504f2..a4a4f14a 100644
--- a/src/dcm/api/keyValueHandler.go
+++ b/src/dcm/api/keyValueHandler.go
@@ -90,6 +90,10 @@ func (h keyValueHandler) getHandler(w http.ResponseWriter, r *http.Request) {
} else {
ret, err = h.client.GetKVPair(project, logicalCloud, name)
if err != nil {
+ if err.Error() == "KV Pair does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -130,12 +134,16 @@ func (h keyValueHandler) updateHandler(w http.ResponseWriter, r *http.Request) {
ret, err := h.client.UpdateKVPair(project, logicalCloud, name, v)
if err != nil {
+ if err.Error() == "KV Pair does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(),
http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(http.StatusCreated)
+ w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(ret)
if err != nil {
http.Error(w, err.Error(),
diff --git a/src/dcm/api/logicalCloudHandler.go b/src/dcm/api/logicalCloudHandler.go
index d9a3e5f5..36ec4e05 100644
--- a/src/dcm/api/logicalCloudHandler.go
+++ b/src/dcm/api/logicalCloudHandler.go
@@ -91,6 +91,10 @@ func (h logicalCloudHandler) getHandler(w http.ResponseWriter, r *http.Request)
} else {
ret, err = h.client.Get(project, name)
if err != nil {
+ if err.Error() == "Logical Cloud does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -129,6 +133,10 @@ func (h logicalCloudHandler) updateHandler(w http.ResponseWriter, r *http.Reques
ret, err := h.client.Update(project, name, v)
if err != nil {
+ if err.Error() == "Logical Cloud does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(),
http.StatusInternalServerError)
return
@@ -150,6 +158,10 @@ func (h logicalCloudHandler) deleteHandler(w http.ResponseWriter, r *http.Reques
err := h.client.Delete(project, name)
if err != nil {
+ if err.Error() == "Logical Cloud does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -165,6 +177,10 @@ func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request
// Get logical cloud
lc, err := h.client.Get(project, name)
if err != nil {
+ if err.Error() == "Logical Cloud does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -173,6 +189,10 @@ func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request
clusters, err := h.clusterClient.GetAllClusters(project, name)
if err != nil {
+ if err.Error() == "No Cluster References associated" {
+ http.Error(w, err.Error(), http.StatusBadRequest)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
diff --git a/src/dcm/api/quotaHandler.go b/src/dcm/api/quotaHandler.go
index deb18e18..fd9b40f8 100644
--- a/src/dcm/api/quotaHandler.go
+++ b/src/dcm/api/quotaHandler.go
@@ -91,6 +91,10 @@ func (h quotaHandler) getHandler(w http.ResponseWriter, r *http.Request) {
} else {
ret, err = h.client.GetQuota(project, logicalCloud, name)
if err != nil {
+ if err.Error() == "Cluster Quota does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -131,12 +135,16 @@ func (h quotaHandler) updateHandler(w http.ResponseWriter, r *http.Request) {
ret, err := h.client.UpdateQuota(project, logicalCloud, name, v)
if err != nil {
+ if err.Error() == "Cluster Quota does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(),
http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(http.StatusCreated)
+ w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(ret)
if err != nil {
http.Error(w, err.Error(),
diff --git a/src/dcm/api/userPermissionsHandler.go b/src/dcm/api/userPermissionsHandler.go
index 156c390f..3ac955fa 100644
--- a/src/dcm/api/userPermissionsHandler.go
+++ b/src/dcm/api/userPermissionsHandler.go
@@ -89,8 +89,12 @@ func (h userPermissionHandler) getHandler(w http.ResponseWriter, r *http.Request
return
}
} else {
- ret, err = h.client.GetAllUserPerms(project, logicalCloud)
+ ret, err = h.client.GetUserPerm(project, logicalCloud, name)
if err != nil {
+ if err.Error() == "User Permission does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -131,12 +135,16 @@ func (h userPermissionHandler) updateHandler(w http.ResponseWriter, r *http.Requ
ret, err := h.client.UpdateUserPerm(project, logicalCloud, name, v)
if err != nil {
+ if err.Error() == "User Permission does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
http.Error(w, err.Error(),
http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(http.StatusCreated)
+ w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(ret)
if err != nil {
http.Error(w, err.Error(),