mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
added json validation and route not found
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user