adding error handling for all DB calls. Returning StatusInternalServerError whenever an error occurs. Adding additional logging to server handlers.

Make sure we "return" after a c.JSON call.
This commit is contained in:
Jason Kulatunga
2020-09-23 09:54:33 -06:00
parent 531fea76b2
commit 6a20228262
6 changed files with 68 additions and 28 deletions
@@ -6,6 +6,7 @@ import (
dbModels "github.com/analogj/scrutiny/webapp/backend/pkg/models/db"
"github.com/analogj/scrutiny/webapp/backend/pkg/notify"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"net/http"
"os"
)
@@ -13,6 +14,7 @@ import (
// Send test notification
func SendTestNotification(c *gin.Context) {
appConfig := c.MustGet("CONFIG").(config.Interface)
logger := c.MustGet("LOGGER").(logrus.FieldLogger)
testNotify := notify.Notify{
Config: appConfig,
@@ -28,7 +30,8 @@ func SendTestNotification(c *gin.Context) {
}
err := testNotify.Send()
if err != nil {
c.JSON(http.StatusOK, gin.H{
logger.Errorln("An error occurred while sending test notification", err)
c.JSON(http.StatusInternalServerError, gin.H{
"success": false,
})
} else {