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
Makefile
1
Makefile
@@ -1,4 +1,5 @@
|
|||||||
# Just builds
|
# Just builds
|
||||||
|
.PHONY: all test dep build
|
||||||
|
|
||||||
DIR := ${CURDIR}
|
DIR := ${CURDIR}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type ErrorBody struct {
|
type ErrorBody struct {
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
RequestID string `json:"request_id,omitempty"`
|
Fields string `json:"fields,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates this error body
|
// Validate validates this error body
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/iron-io/functions/api"
|
"github.com/iron-io/functions/api"
|
||||||
@@ -24,6 +22,11 @@ import (
|
|||||||
uuid "github.com/satori/go.uuid"
|
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) {
|
func (s *Server) handleSpecial(c *gin.Context) {
|
||||||
ctx := c.MustGet("ctx").(context.Context)
|
ctx := c.MustGet("ctx").(context.Context)
|
||||||
log := common.Logger(ctx)
|
log := common.Logger(ctx)
|
||||||
@@ -232,19 +235,19 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
|
|||||||
case "success":
|
case "success":
|
||||||
c.Data(http.StatusOK, "", stdout.Bytes())
|
c.Data(http.StatusOK, "", stdout.Bytes())
|
||||||
case "timeout":
|
case "timeout":
|
||||||
c.AbortWithStatus(http.StatusGatewayTimeout)
|
c.JSON(http.StatusGatewayTimeout, runnerResponse{
|
||||||
default:
|
|
||||||
errMsg := &models.ErrorBody{
|
|
||||||
Message: result.Error(),
|
|
||||||
RequestID: cfg.ID,
|
RequestID: cfg.ID,
|
||||||
}
|
Error: &models.ErrorBody{
|
||||||
|
Message: models.ErrRunnerTimeout.Error(),
|
||||||
errStr, err := json.Marshal(errMsg)
|
},
|
||||||
if err != nil {
|
})
|
||||||
c.AbortWithStatus(http.StatusInternalServerError)
|
default:
|
||||||
}
|
c.JSON(http.StatusInternalServerError, runnerResponse{
|
||||||
|
RequestID: cfg.ID,
|
||||||
c.Data(http.StatusInternalServerError, "", errStr)
|
Error: &models.ErrorBody{
|
||||||
|
Message: result.Error(),
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user