chore(web): use errors.As instead of type assertion
(cherry picked from commit 57ba073874c23772b2b80bc12be8578860e9c7ec)
This commit is contained in:
parent
198b2e3b70
commit
5768648760
@ -56,7 +56,7 @@ func Login(c echo.Context) error {
|
|||||||
user, err := user2.CheckUserCredentials(s, &u)
|
user, err := user2.CheckUserCredentials(s, &u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = s.Rollback()
|
_ = s.Rollback()
|
||||||
return handler.HandleHTTPError(err, c)
|
return handler.HandleHTTPError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.Status == user2.StatusDisabled {
|
if user.Status == user2.StatusDisabled {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -31,7 +32,8 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
|||||||
// Get the object & bind params to struct
|
// Get the object & bind params to struct
|
||||||
if err := ctx.Bind(currentStruct); err != nil {
|
if err := ctx.Bind(currentStruct); err != nil {
|
||||||
config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
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. Error was: %s", he.Message))
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided."))
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided."))
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -36,7 +37,8 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
|
|||||||
// Bind params to struct
|
// Bind params to struct
|
||||||
if err := ctx.Bind(currentStruct); err != nil {
|
if err := ctx.Bind(currentStruct); err != nil {
|
||||||
config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
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. Error was: %s", he.Message))
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided."))
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided."))
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -38,7 +39,8 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
|||||||
// Get the object & bind params to struct
|
// Get the object & bind params to struct
|
||||||
if err := ctx.Bind(currentStruct); err != nil {
|
if err := ctx.Bind(currentStruct); err != nil {
|
||||||
config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
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. Error was: %s", he.Message))
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided."))
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided."))
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -32,7 +33,8 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
|||||||
// Get the object & bind params to struct
|
// Get the object & bind params to struct
|
||||||
if err := ctx.Bind(currentStruct); err != nil {
|
if err := ctx.Bind(currentStruct); err != nil {
|
||||||
config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
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. Error was: %s", he.Message))
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided."))
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided."))
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -32,7 +33,8 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
|||||||
// Get the object & bind params to struct
|
// Get the object & bind params to struct
|
||||||
if err := ctx.Bind(currentStruct); err != nil {
|
if err := ctx.Bind(currentStruct); err != nil {
|
||||||
config.LoggingProvider.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
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. Error was: %s", he.Message))
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided."))
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid model provided."))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user