From d6ab81a0f907ce129086ab5ad31e9d6ec81d19f4 Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Tue, 19 Oct 2021 11:17:31 +0200 Subject: [PATCH] fix in health endpoint (error handling) and scenario duplication --- routes/healthz/healthz_endpoint.go | 18 ++++++++++++++---- routes/user/scenario_duplication.go | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/routes/healthz/healthz_endpoint.go b/routes/healthz/healthz_endpoint.go index efe13cf..bd25bad 100644 --- a/routes/healthz/healthz_endpoint.go +++ b/routes/healthz/healthz_endpoint.go @@ -22,6 +22,7 @@ package healthz import ( + "fmt" "log" "net/http" "strings" @@ -74,15 +75,24 @@ func getHealth(c *gin.Context) { } if len(url) != 0 { - err = session.CheckConnection() - if err != nil { - log.Println(err.Error()) + if session != nil { + err = session.CheckConnection() + if err != nil { + log.Println(err.Error()) + c.JSON(http.StatusInternalServerError, gin.H{ + "success:": false, + "message": err.Error(), + }) + return + } + } else { c.JSON(http.StatusInternalServerError, gin.H{ "success:": false, - "message": err.Error(), + "message": fmt.Errorf("AMQP session is nil"), }) return } + } // Send a 204 reponse diff --git a/routes/user/scenario_duplication.go b/routes/user/scenario_duplication.go index 2dcbd82..7b0b4a4 100644 --- a/routes/user/scenario_duplication.go +++ b/routes/user/scenario_duplication.go @@ -57,7 +57,7 @@ func duplicateScenarioForUser(s database.Scenario, user *database.User) <-chan e err = db.Find(&ic, icID).Error if err != nil { - errs <- fmt.Errorf("Cannot find IC with id %d in DB, will not duplicate for User %s: %s", icID, user.Username, err) + log.Printf("Cannot find IC with id %d in DB, will not duplicate for User %s: %s", icID, user.Username, err) continue }