From 4734a0a6a6982e1c0777e32700f1ee3fe256c953 Mon Sep 17 00:00:00 2001 From: konrad Date: Wed, 11 Jul 2018 14:27:16 +0200 Subject: [PATCH] use echo.NewHTTPError --- routes/crud/create.go | 2 +- routes/crud/delete.go | 2 +- routes/crud/read_all.go | 4 ++-- routes/crud/read_one.go | 6 +++--- routes/crud/update.go | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/routes/crud/create.go b/routes/crud/create.go index 39e5202426f..e3735667b74 100644 --- a/routes/crud/create.go +++ b/routes/crud/create.go @@ -10,7 +10,7 @@ import ( func (c *WebHandler) CreateWeb(ctx echo.Context) error { // Get the object if err := ctx.Bind(&c.CObject); err != nil { - return ctx.JSON(http.StatusBadRequest, models.Message{"No model provided."}) + return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.") } // Get the user to pass for later checks diff --git a/routes/crud/delete.go b/routes/crud/delete.go index 95d895be52a..c384684af16 100644 --- a/routes/crud/delete.go +++ b/routes/crud/delete.go @@ -11,7 +11,7 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error { // Get the ID id, err := models.GetIntURLParam("id", ctx) if err != nil { - return ctx.JSON(http.StatusBadRequest, models.Message{"Invalid ID."}) + return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID.") } // Check if the user has the right to delete diff --git a/routes/crud/read_all.go b/routes/crud/read_all.go index 770db64484b..195ecccdc1b 100644 --- a/routes/crud/read_all.go +++ b/routes/crud/read_all.go @@ -10,12 +10,12 @@ import ( func (c *WebHandler) ReadAllWeb(ctx echo.Context) error { currentUser, err := models.GetCurrentUser(ctx) if err != nil { - return ctx.JSON(http.StatusInternalServerError, models.Message{"Could not determine the current user."}) + return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.") } lists, err := c.CObject.ReadAll(¤tUser) if err != nil { - return ctx.JSON(http.StatusInternalServerError, models.Message{"Could not get."}) + return echo.NewHTTPError(http.StatusInternalServerError, "An error occured.") } return ctx.JSON(http.StatusOK, lists) diff --git a/routes/crud/read_one.go b/routes/crud/read_one.go index d78c7799467..d1a77f84be6 100644 --- a/routes/crud/read_one.go +++ b/routes/crud/read_one.go @@ -12,7 +12,7 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error { // Get the ID id, err := models.GetIntURLParam("id", ctx) if err != nil { - return ctx.JSON(http.StatusBadRequest, models.Message{"Invalid ID."}) + return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID.") } // TODO check rights @@ -21,10 +21,10 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error { err = c.CObject.ReadOne(id) if err != nil { if models.IsErrListDoesNotExist(err) { - return ctx.JSON(http.StatusNotFound, models.Message{"Not found."}) + return echo.NewHTTPError(http.StatusNotFound) } - return ctx.JSON(http.StatusInternalServerError, models.Message{"An error occured."}) + return echo.NewHTTPError(http.StatusInternalServerError, "An error occured.") } return ctx.JSON(http.StatusOK, c.CObject) diff --git a/routes/crud/update.go b/routes/crud/update.go index 282013ae5ad..c0434bb921b 100644 --- a/routes/crud/update.go +++ b/routes/crud/update.go @@ -11,19 +11,19 @@ import ( func (c *WebHandler) UpdateWeb(ctx echo.Context) error { // Get the object if err := ctx.Bind(&c.CObject); err != nil { - return ctx.JSON(http.StatusBadRequest, models.Message{"No model provided."}) + return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.") } // Get the ID id, err := models.GetIntURLParam("id", ctx) if err != nil { - return ctx.JSON(http.StatusBadRequest, models.Message{"Invalid ID."}) + return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID.") } // Check if the user has the right to do that currentUser, err := models.GetCurrentUser(ctx) if err != nil { - return ctx.JSON(http.StatusInternalServerError, models.Message{"Could not determine the current user."}) + return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.") } // Do the update