fix in health endpoint (error handling) and scenario duplication

This commit is contained in:
Sonja Happ 2021-10-19 11:17:31 +02:00
parent e7679a79b7
commit d6ab81a0f9
2 changed files with 15 additions and 5 deletions

View file

@ -22,6 +22,7 @@
package healthz package healthz
import ( import (
"fmt"
"log" "log"
"net/http" "net/http"
"strings" "strings"
@ -74,6 +75,7 @@ func getHealth(c *gin.Context) {
} }
if len(url) != 0 { if len(url) != 0 {
if session != nil {
err = session.CheckConnection() err = session.CheckConnection()
if err != nil { if err != nil {
log.Println(err.Error()) log.Println(err.Error())
@ -83,6 +85,14 @@ func getHealth(c *gin.Context) {
}) })
return return
} }
} else {
c.JSON(http.StatusInternalServerError, gin.H{
"success:": false,
"message": fmt.Errorf("AMQP session is nil"),
})
return
}
} }
// Send a 204 reponse // Send a 204 reponse

View file

@ -57,7 +57,7 @@ func duplicateScenarioForUser(s database.Scenario, user *database.User) <-chan e
err = db.Find(&ic, icID).Error err = db.Find(&ic, icID).Error
if err != nil { 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 continue
} }