mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fix runner response (#517)
This commit is contained in:
committed by
Seif Lotfy سيف لطفي
parent
ad50523fd1
commit
a5eeacdadb
@@ -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
|
||||
|
||||
@@ -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(),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user