From 616d9df8fa0f30f01c8b1056f5852e493d7268c5 Mon Sep 17 00:00:00 2001 From: Pedro Nasser Date: Sat, 30 Jul 2016 18:57:59 -0300 Subject: [PATCH] added json validation and route not found --- api/server/router/runner.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/api/server/router/runner.go b/api/server/router/runner.go index 85c391f96..03150254f 100644 --- a/api/server/router/runner.go +++ b/api/server/router/runner.go @@ -6,6 +6,8 @@ import ( "strings" "time" + "encoding/json" + "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" "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") appName := c.Param("app") @@ -60,6 +71,11 @@ func handleRunner(c *gin.Context) { 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") for _, el := range routes {