aboutsummaryrefslogtreecommitdiffstats
path: root/src/dcm/api/keyValueHandler.go
diff options
context:
space:
mode:
authorIgor D.C <igor.duarte.cardoso@intel.com>2020-09-25 00:04:58 +0000
committerIgor D.C <igor.duarte.cardoso@intel.com>2020-09-25 05:28:52 +0000
commitc585d2b091875dbc9575a960f4f42c1f14ec3366 (patch)
treeaba0039b6477dfbc2790cd5efc365a6d9ccb4390 /src/dcm/api/keyValueHandler.go
parentab8142dfc0f54bfc140e240fe558ac5be8d60ea5 (diff)
Enhance error handling and HTTP codes in DCM
This improves error handling between DCM and the database resources and adds/corrects a lot more HTTP return codes in the API, respectively. Issue-ID: MULTICLOUD-1143 Change-Id: I3abc8025660e042f4c946f8bbfd280e1eb4c9583 Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
Diffstat (limited to 'src/dcm/api/keyValueHandler.go')
-rw-r--r--src/dcm/api/keyValueHandler.go10
1 files changed, 9 insertions, 1 deletions
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(),