chore(errors): always add internal error to echo error
(cherry picked from commit 7a7e97770c9ecc10e805069ae16c2ffa2779d2a5)
This commit is contained in:
@ -34,12 +34,12 @@ func DocsJSON(c echo.Context) error {
|
||||
doc, err := swag.ReadDoc()
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError).SetInternal(err)
|
||||
}
|
||||
_, err = c.Response().Write([]byte(doc))
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError).SetInternal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -45,7 +45,7 @@ func UploadTaskAttachment(c echo.Context) error {
|
||||
|
||||
var taskAttachment models.TaskAttachment
|
||||
if err := c.Bind(&taskAttachment); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No task ID provided")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No task ID provided").SetInternal(err)
|
||||
}
|
||||
|
||||
// Rights check
|
||||
@ -125,7 +125,7 @@ func GetTaskAttachment(c echo.Context) error {
|
||||
|
||||
var taskAttachment models.TaskAttachment
|
||||
if err := c.Bind(&taskAttachment); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No task ID provided")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No task ID provided").SetInternal(err)
|
||||
}
|
||||
|
||||
// Rights check
|
||||
|
@ -42,7 +42,7 @@ func UserConfirmEmail(c echo.Context) error {
|
||||
// Check for Request Content
|
||||
var emailConfirm user.EmailConfirm
|
||||
if err := c.Bind(&emailConfirm); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No token provided.")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No token provided.").SetInternal(err)
|
||||
}
|
||||
|
||||
s := db.NewSession()
|
||||
|
@ -65,18 +65,18 @@ func UserRequestDeletion(c echo.Context) error {
|
||||
if u.IsLocalUser() {
|
||||
var deletionRequest UserPasswordConfirmation
|
||||
if err := c.Bind(&deletionRequest); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No password provided.")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No password provided.").SetInternal(err)
|
||||
}
|
||||
|
||||
err = c.Validate(deletionRequest)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err).SetInternal(err)
|
||||
}
|
||||
|
||||
err = user.CheckUserPassword(u, deletionRequest.Password)
|
||||
if err != nil {
|
||||
_ = s.Rollback()
|
||||
return handler.HandleHTTPError(err, c)
|
||||
return handler.HandleHTTPError(err, c).SetInternal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,12 +109,12 @@ func UserRequestDeletion(c echo.Context) error {
|
||||
func UserConfirmDeletion(c echo.Context) error {
|
||||
var deleteConfirmation UserDeletionRequestConfirm
|
||||
if err := c.Bind(&deleteConfirmation); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No token provided.")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No token provided.").SetInternal(err)
|
||||
}
|
||||
|
||||
err := c.Validate(deleteConfirmation)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err).SetInternal(err)
|
||||
}
|
||||
|
||||
s := db.NewSession()
|
||||
@ -176,12 +176,12 @@ func UserCancelDeletion(c echo.Context) error {
|
||||
if u.IsLocalUser() {
|
||||
var deletionRequest UserPasswordConfirmation
|
||||
if err := c.Bind(&deletionRequest); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No password provided.")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No password provided.").SetInternal(err)
|
||||
}
|
||||
|
||||
err = c.Validate(deletionRequest)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err).SetInternal(err)
|
||||
}
|
||||
|
||||
err = user.CheckUserPassword(u, deletionRequest.Password)
|
||||
|
@ -51,12 +51,12 @@ func checkExportRequest(c echo.Context) (s *xorm.Session, u *user.User, err erro
|
||||
|
||||
var pass UserPasswordConfirmation
|
||||
if err := c.Bind(&pass); err != nil {
|
||||
return nil, nil, echo.NewHTTPError(http.StatusBadRequest, "No password provided.")
|
||||
return nil, nil, echo.NewHTTPError(http.StatusBadRequest, "No password provided.").SetInternal(err)
|
||||
}
|
||||
|
||||
err = c.Validate(pass)
|
||||
if err != nil {
|
||||
return nil, nil, echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
return nil, nil, echo.NewHTTPError(http.StatusBadRequest, err).SetInternal(err)
|
||||
}
|
||||
|
||||
err = user.CheckUserPassword(u, pass.Password)
|
||||
|
@ -42,7 +42,7 @@ func UserResetPassword(c echo.Context) error {
|
||||
// Check for Request Content
|
||||
var pwReset user.PasswordReset
|
||||
if err := c.Bind(&pwReset); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No password provided.")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No password provided.").SetInternal(err)
|
||||
}
|
||||
|
||||
s := db.NewSession()
|
||||
@ -77,11 +77,11 @@ func UserRequestResetPasswordToken(c echo.Context) error {
|
||||
// Check for Request Content
|
||||
var pwTokenReset user.PasswordTokenRequest
|
||||
if err := c.Bind(&pwTokenReset); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No username provided.")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No username provided.").SetInternal(err)
|
||||
}
|
||||
|
||||
if err := c.Validate(pwTokenReset); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err).SetInternal(err)
|
||||
}
|
||||
|
||||
s := db.NewSession()
|
||||
|
@ -116,7 +116,7 @@ func ChangeUserAvatarProvider(c echo.Context) error {
|
||||
uap := &UserAvatarProvider{}
|
||||
err := c.Bind(uap)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Bad avatar type provided.")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Bad avatar type provided.").SetInternal(err)
|
||||
}
|
||||
|
||||
u, err := user2.GetCurrentUser(c)
|
||||
@ -166,14 +166,14 @@ func UpdateGeneralUserSettings(c echo.Context) error {
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
err = c.Validate(us)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err)
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err).SetInternal(err)
|
||||
}
|
||||
|
||||
u, err := user2.GetCurrentUser(c)
|
||||
|
@ -52,7 +52,7 @@ type userWithSettings struct {
|
||||
func UserShow(c echo.Context) error {
|
||||
a, err := auth.GetAuthFromClaims(c)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Error getting current user.")
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Error getting current user.").SetInternal(err)
|
||||
}
|
||||
|
||||
s := db.NewSession()
|
||||
|
@ -94,9 +94,9 @@ func UserTOTPEnable(c 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)
|
||||
}
|
||||
|
||||
s := db.NewSession()
|
||||
@ -135,9 +135,9 @@ func UserTOTPDisable(c 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)
|
||||
}
|
||||
|
||||
u, err := user.GetCurrentUser(c)
|
||||
|
@ -50,9 +50,9 @@ func UpdateUserEmail(c echo.Context) (err 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)
|
||||
}
|
||||
|
||||
emailUpdate.User, err = user.GetCurrentUser(c)
|
||||
|
@ -50,13 +50,13 @@ func UserChangePassword(c echo.Context) error {
|
||||
// Check if the user is itself
|
||||
doer, err := user.GetCurrentUser(c)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Error getting current user.")
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Error getting current user.").SetInternal(err)
|
||||
}
|
||||
|
||||
// Check for Request Content
|
||||
var newPW UserPassword
|
||||
if err := c.Bind(&newPW); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No password provided.")
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No password provided.").SetInternal(err)
|
||||
}
|
||||
|
||||
if newPW.OldPassword == "" {
|
||||
|
Reference in New Issue
Block a user