1
0

chore(web): always set internal error

(cherry picked from commit 5c56d07215a2a1fac63c565eac669fe8c1f19cbc)
This commit is contained in:
kolaente
2024-09-01 19:36:26 +02:00
parent a2ef74cade
commit 5049cbf236
6 changed files with 21 additions and 21 deletions

View File

@ -38,7 +38,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
currentAuth, err := auth.GetAuthFromClaims(ctx)
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
@ -46,9 +46,9 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
log.Debugf("Invalid model error. Internal error was: %s", err.Error())
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)).SetInternal(err)
}
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.")
return echo.NewHTTPError(http.StatusBadRequest, "Invalid model provided.").SetInternal(err)
}
// Pagination
@ -59,7 +59,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
pageNumber, err := strconv.Atoi(page)
if err != nil {
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 {
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)
if err != nil {
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