fix runner response (#517)

This commit is contained in:
Pedro Nasser
2017-02-11 00:36:56 -02:00
committed by Seif Lotfy سيف لطفي
parent ad50523fd1
commit a5eeacdadb
3 changed files with 20 additions and 16 deletions

View File

@@ -1,8 +1,8 @@
package models
type ErrorBody struct {
Message string `json:"message,omitempty"`
RequestID string `json:"request_id,omitempty"`
Message string `json:"message,omitempty"`
Fields string `json:"fields,omitempty"`
}
// Validate validates this error body

View File

@@ -12,8 +12,6 @@ import (
"strings"
"time"
"encoding/json"
"github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api"
@@ -24,6 +22,11 @@ import (
uuid "github.com/satori/go.uuid"
)
type runnerResponse struct {
RequestID string `json:"request_id,omitempty"`
Error *models.ErrorBody `json:"error,omitempty"`
}
func (s *Server) handleSpecial(c *gin.Context) {
ctx := c.MustGet("ctx").(context.Context)
log := common.Logger(ctx)
@@ -232,19 +235,19 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
case "success":
c.Data(http.StatusOK, "", stdout.Bytes())
case "timeout":
c.AbortWithStatus(http.StatusGatewayTimeout)
default:
errMsg := &models.ErrorBody{
Message: result.Error(),
c.JSON(http.StatusGatewayTimeout, runnerResponse{
RequestID: cfg.ID,
}
errStr, err := json.Marshal(errMsg)
if err != nil {
c.AbortWithStatus(http.StatusInternalServerError)
}
c.Data(http.StatusInternalServerError, "", errStr)
Error: &models.ErrorBody{
Message: models.ErrRunnerTimeout.Error(),
},
})
default:
c.JSON(http.StatusInternalServerError, runnerResponse{
RequestID: cfg.ID,
Error: &models.ErrorBody{
Message: result.Error(),
},
})
}
}