New error handling added to getRequestBody function in data package

This commit is contained in:
Héctor Hurtado
2019-11-18 15:01:02 +01:00
parent e4b3a4f718
commit 4c7eae8ebb
3 changed files with 5 additions and 5 deletions
+2 -1
View File
@@ -24,6 +24,7 @@ import (
"strconv"
"github.com/BBVA/kapow/internal/server/model"
"github.com/BBVA/kapow/internal/server/srverrors"
"github.com/gorilla/mux"
)
@@ -32,7 +33,7 @@ func getRequestBody(w http.ResponseWriter, r *http.Request, h *model.Handler) {
n, err := io.Copy(w, h.Request.Body)
if err != nil {
if n == 0 {
w.WriteHeader(http.StatusInternalServerError)
srverrors.WriteErrorResponse(http.StatusInternalServerError, "Internal Server Error", w)
} else {
// Only way to abort current connection as of go 1.13
// https://github.com/golang/go/issues/16542