From a5eeacdadbc899907ebfbd29b1de21acc8a24594 Mon Sep 17 00:00:00 2001 From: Pedro Nasser Date: Sat, 11 Feb 2017 00:36:56 -0200 Subject: [PATCH] fix runner response (#517) --- Makefile | 1 + api/models/error_body.go | 4 ++-- api/server/runner.go | 31 +++++++++++++++++-------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index d2246f97d..bd44e13a0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ # Just builds +.PHONY: all test dep build DIR := ${CURDIR} diff --git a/api/models/error_body.go b/api/models/error_body.go index 3188d6ff2..3ba31d60b 100644 --- a/api/models/error_body.go +++ b/api/models/error_body.go @@ -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 diff --git a/api/server/runner.go b/api/server/runner.go index 299b8dcec..6b800632d 100644 --- a/api/server/runner.go +++ b/api/server/runner.go @@ -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(), + }, + }) } }