diff --git a/handler/create.go b/handler/create.go index 6a2bc03..73de234 100644 --- a/handler/create.go +++ b/handler/create.go @@ -16,6 +16,7 @@ package handler import ( + "fmt" "github.com/labstack/echo/v4" "net/http" ) @@ -27,7 +28,11 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error { // Get the object & bind params to struct if err := ctx.Bind(currentStruct); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.") + config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error()) + if he, is := err.(*echo.HTTPError); is { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided. Error was: %s", he.Message)) + } + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided.")) } // Validate the struct diff --git a/handler/delete.go b/handler/delete.go index 6053bc0..cc71617 100644 --- a/handler/delete.go +++ b/handler/delete.go @@ -16,6 +16,7 @@ package handler import ( + "fmt" "github.com/labstack/echo/v4" "net/http" ) @@ -32,7 +33,11 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error { // Bind params to struct if err := ctx.Bind(currentStruct); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "Invalid URL param.") + config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error()) + if he, is := err.(*echo.HTTPError); is { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided. Error was: %s", he.Message)) + } + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided.")) } // Check if the user has the right to delete diff --git a/handler/read_all.go b/handler/read_all.go index 001b60f..c7d00b0 100644 --- a/handler/read_all.go +++ b/handler/read_all.go @@ -16,6 +16,7 @@ package handler import ( + "fmt" "github.com/labstack/echo/v4" "math" "net/http" @@ -34,7 +35,11 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error { // Get the object & bind params to struct if err := ctx.Bind(currentStruct); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.") + config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error()) + if he, is := err.(*echo.HTTPError); is { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided. Error was: %s", he.Message)) + } + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided.")) } // Pagination diff --git a/handler/read_one.go b/handler/read_one.go index 6de14ec..4a59e28 100644 --- a/handler/read_one.go +++ b/handler/read_one.go @@ -16,6 +16,7 @@ package handler import ( + "fmt" "github.com/labstack/echo/v4" "net/http" ) @@ -27,7 +28,11 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error { // Get the object & bind params to struct if err := ctx.Bind(currentStruct); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.") + config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error()) + if he, is := err.(*echo.HTTPError); is { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided. Error was: %s", he.Message)) + } + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided.")) } // Check rights diff --git a/handler/update.go b/handler/update.go index 189fa12..9de1160 100644 --- a/handler/update.go +++ b/handler/update.go @@ -16,6 +16,7 @@ package handler import ( + "fmt" "github.com/labstack/echo/v4" "net/http" ) @@ -28,7 +29,11 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error { // Get the object & bind params to struct if err := ctx.Bind(currentStruct); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.") + config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error()) + if he, is := err.(*echo.HTTPError); is { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided. Error was: %s", he.Message)) + } + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided.")) } // Validate the struct