chore(web): always set internal error
(cherry picked from commit 5c56d07215a2a1fac63c565eac669fe8c1f19cbc)
This commit is contained in:
parent
a2ef74cade
commit
5049cbf236
@ -38,20 +38,20 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
|||||||
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
||||||
var he *echo.HTTPError
|
var he *echo.HTTPError
|
||||||
if errors.As(err, &he) {
|
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)).SetInternal(err)
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the struct
|
// Validate the struct
|
||||||
if err := ctx.Validate(currentStruct); err != nil {
|
if err := ctx.Validate(currentStruct); err != nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
return echo.NewHTTPError(http.StatusBadRequest, err).SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the user to pass for later checks
|
// Get the user to pass for later checks
|
||||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the db session
|
// Create the db session
|
||||||
|
@ -43,15 +43,15 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
|
|||||||
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
||||||
var he *echo.HTTPError
|
var he *echo.HTTPError
|
||||||
if errors.As(err, &he) {
|
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)).SetInternal(err)
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the user has the right to delete
|
// Check if the user has the right to delete
|
||||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
return echo.NewHTTPError(http.StatusInternalServerError).SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the db session
|
// Create the db session
|
||||||
|
@ -42,7 +42,7 @@ func HandleHTTPError(err error) *echo.HTTPError {
|
|||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
if a, has := err.(web.HTTPErrorProcessor); has {
|
if a, has := err.(web.HTTPErrorProcessor); has {
|
||||||
errDetails := a.HTTPError()
|
errDetails := a.HTTPError()
|
||||||
return echo.NewHTTPError(errDetails.HTTPCode, errDetails)
|
return echo.NewHTTPError(errDetails.HTTPCode, errDetails).SetInternal(err)
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
return echo.NewHTTPError(http.StatusInternalServerError).SetInternal(err)
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
|||||||
|
|
||||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the object & bind params to struct
|
// Get the object & bind params to struct
|
||||||
@ -46,9 +46,9 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
|||||||
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
||||||
var he *echo.HTTPError
|
var he *echo.HTTPError
|
||||||
if errors.As(err, &he) {
|
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)).SetInternal(err)
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pagination
|
// Pagination
|
||||||
@ -59,7 +59,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
|||||||
pageNumber, err := strconv.Atoi(page)
|
pageNumber, err := strconv.Atoi(page)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Bad page requested.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Bad page requested.").SetInternal(err)
|
||||||
}
|
}
|
||||||
if pageNumber < 0 {
|
if pageNumber < 0 {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Page number cannot be negative.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Page number cannot be negative.")
|
||||||
@ -74,7 +74,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
|||||||
perPageNumber, err = strconv.Atoi(perPage)
|
perPageNumber, err = strconv.Atoi(perPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Bad per page amount requested.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Bad per page amount requested.").SetInternal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set default page count
|
// Set default page count
|
||||||
|
@ -39,15 +39,15 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
|||||||
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
||||||
var he *echo.HTTPError
|
var he *echo.HTTPError
|
||||||
if errors.As(err, &he) {
|
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)).SetInternal(err)
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check rights
|
// Check rights
|
||||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the db session
|
// Create the db session
|
||||||
|
@ -39,20 +39,20 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
|||||||
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
|
||||||
var he *echo.HTTPError
|
var he *echo.HTTPError
|
||||||
if errors.As(err, &he) {
|
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)).SetInternal(err)
|
||||||
}
|
}
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the struct
|
// Validate the struct
|
||||||
if err := ctx.Validate(currentStruct); err != nil {
|
if err := ctx.Validate(currentStruct); err != nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
return echo.NewHTTPError(http.StatusBadRequest, err).SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the user has the right to do that
|
// Check if the user has the right to do that
|
||||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the db session
|
// Create the db session
|
||||||
|
Loading…
x
Reference in New Issue
Block a user