added json validation and route not found

This commit is contained in:
Pedro Nasser
2016-07-30 18:57:59 -03:00
parent d2babb33ce
commit 616d9df8fa

View File

@@ -6,6 +6,8 @@ import (
"strings" "strings"
"time" "time"
"encoding/json"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/models" "github.com/iron-io/functions/api/models"
@@ -34,6 +36,15 @@ func handleRunner(c *gin.Context) {
} }
} }
if len(payload) > 0 {
var emptyJson map[string]interface{}
if err := json.Unmarshal(payload, &emptyJson); err != nil {
log.WithError(err).Error(models.ErrInvalidJSON)
c.JSON(http.StatusBadRequest, simpleError(models.ErrInvalidJSON))
return
}
}
log.WithField("payload", string(payload)).Debug("Got payload") log.WithField("payload", string(payload)).Debug("Got payload")
appName := c.Param("app") appName := c.Param("app")
@@ -60,6 +71,11 @@ func handleRunner(c *gin.Context) {
c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesList)) c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesList))
} }
if routes == nil || len(routes) == 0 {
log.WithError(err).Error(models.ErrRunnerRouteNotFound)
c.JSON(http.StatusNotFound, simpleError(models.ErrRunnerRouteNotFound))
}
log.WithField("routes", routes).Debug("Got routes from datastore") log.WithField("routes", routes).Debug("Got routes from datastore")
for _, el := range routes { for _, el := range routes {