From c585d2b091875dbc9575a960f4f42c1f14ec3366 Mon Sep 17 00:00:00 2001 From: "Igor D.C" Date: Fri, 25 Sep 2020 00:04:58 +0000 Subject: 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 --- src/dcm/api/clusterHandler.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/dcm/api/clusterHandler.go') 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(), -- cgit 1.2.3-korg