Fix datastore error for inexistent app (#493)

* fix datastore error inexistent app

* fix get route error handling

* fix API errors handling and tests
This commit is contained in:
Pedro Nasser
2017-01-26 20:41:18 -02:00
committed by Travis Reeder
parent 5a91710dbf
commit a80fe9c897
15 changed files with 65 additions and 100 deletions

View File

@@ -7,25 +7,17 @@ import (
"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api"
"github.com/iron-io/functions/api/models"
"github.com/iron-io/runner/common"
)
func (s *Server) handleRouteGet(c *gin.Context) {
ctx := c.MustGet("ctx").(context.Context)
log := common.Logger(ctx)
appName := c.MustGet(api.AppName).(string)
routePath := path.Clean(c.MustGet(api.Path).(string))
route, err := s.Datastore.GetRoute(ctx, appName, routePath)
if err != nil && err != models.ErrRoutesNotFound {
log.WithError(err).Error(models.ErrRoutesGet)
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
return
} else if route == nil {
log.Debug(models.ErrRoutesNotFound)
c.JSON(http.StatusNotFound, simpleError(models.ErrRoutesNotFound))
if err != nil {
handleErrorResponse(c, err)
return
}