Add error logging for invalid model errors

This commit is contained in:
kolaente 2020-01-26 20:07:57 +01:00
parent f337750c35
commit 9947104b77
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
5 changed files with 30 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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