diff options
author | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-09-25 00:04:58 +0000 |
---|---|---|
committer | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-09-25 05:28:52 +0000 |
commit | c585d2b091875dbc9575a960f4f42c1f14ec3366 (patch) | |
tree | aba0039b6477dfbc2790cd5efc365a6d9ccb4390 /src/dcm/api/logicalCloudHandler.go | |
parent | ab8142dfc0f54bfc140e240fe558ac5be8d60ea5 (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/logicalCloudHandler.go')
-rw-r--r-- | src/dcm/api/logicalCloudHandler.go | 20 |
1 files changed, 20 insertions, 0 deletions
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 } |