diff --git a/pkg/routes/api/v1/login.go b/pkg/routes/api/v1/login.go index f968ce562..fdc7be0b9 100644 --- a/pkg/routes/api/v1/login.go +++ b/pkg/routes/api/v1/login.go @@ -56,7 +56,7 @@ func Login(c echo.Context) error { user, err := user2.CheckUserCredentials(s, &u) if err != nil { _ = s.Rollback() - return handler.HandleHTTPError(err, c) + return handler.HandleHTTPError(err) } if user.Status == user2.StatusDisabled { diff --git a/pkg/web/handler/create.go b/pkg/web/handler/create.go index f2e6fb3e1..1ffe6089c 100644 --- a/pkg/web/handler/create.go +++ b/pkg/web/handler/create.go @@ -17,6 +17,7 @@ package handler import ( + "errors" "fmt" "net/http" @@ -31,7 +32,8 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error { // Get the object & bind params to struct if err := ctx.Bind(currentStruct); err != nil { config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error()) - if he, is := err.(*echo.HTTPError); is { + var he *echo.HTTPError + if errors.As(err, &he) { 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.")) diff --git a/pkg/web/handler/delete.go b/pkg/web/handler/delete.go index e617d9262..ac4bb8497 100644 --- a/pkg/web/handler/delete.go +++ b/pkg/web/handler/delete.go @@ -17,6 +17,7 @@ package handler import ( + "errors" "fmt" "net/http" @@ -36,7 +37,8 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error { // Bind params to struct if err := ctx.Bind(currentStruct); err != nil { config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error()) - if he, is := err.(*echo.HTTPError); is { + var he *echo.HTTPError + if errors.As(err, &he) { 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.")) diff --git a/pkg/web/handler/read_all.go b/pkg/web/handler/read_all.go index 585077e9c..e073c057c 100644 --- a/pkg/web/handler/read_all.go +++ b/pkg/web/handler/read_all.go @@ -17,6 +17,7 @@ package handler import ( + "errors" "fmt" "math" "net/http" @@ -38,7 +39,8 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error { // Get the object & bind params to struct if err := ctx.Bind(currentStruct); err != nil { config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error()) - if he, is := err.(*echo.HTTPError); is { + var he *echo.HTTPError + if errors.As(err, &he) { 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.")) diff --git a/pkg/web/handler/read_one.go b/pkg/web/handler/read_one.go index cc38bb067..2e4fbb766 100644 --- a/pkg/web/handler/read_one.go +++ b/pkg/web/handler/read_one.go @@ -17,6 +17,7 @@ package handler import ( + "errors" "fmt" "net/http" "strconv" @@ -32,7 +33,8 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error { // Get the object & bind params to struct if err := ctx.Bind(currentStruct); err != nil { config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error()) - if he, is := err.(*echo.HTTPError); is { + var he *echo.HTTPError + if errors.As(err, &he) { 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.")) diff --git a/pkg/web/handler/update.go b/pkg/web/handler/update.go index c36bd3754..08f5f7859 100644 --- a/pkg/web/handler/update.go +++ b/pkg/web/handler/update.go @@ -17,6 +17,7 @@ package handler import ( + "errors" "fmt" "net/http" @@ -32,7 +33,8 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error { // Get the object & bind params to struct if err := ctx.Bind(currentStruct); err != nil { config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error()) - if he, is := err.(*echo.HTTPError); is { + var he *echo.HTTPError + if errors.As(err, &he) { 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."))