chore(errors): always add internal error to echo error
(cherry picked from commit 7a7e97770c9ecc10e805069ae16c2ffa2779d2a5)
This commit is contained in:
parent
39d0409f57
commit
cfa58ae599
@ -64,7 +64,7 @@ func (bp *BackgroundProvider) SearchBackgrounds(c echo.Context) error {
|
||||
|
||||
err := c.Bind(p)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided: "+err.Error())
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided: "+err.Error()).SetInternal(err)
|
||||
}
|
||||
|
||||
search := c.QueryParam("s")
|
||||
@ -73,7 +73,7 @@ func (bp *BackgroundProvider) SearchBackgrounds(c echo.Context) error {
|
||||
if pg != "" {
|
||||
page, err = strconv.ParseInt(pg, 10, 64)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid page number: "+err.Error())
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Invalid page number: "+err.Error()).SetInternal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,12 +83,12 @@ func (bp *BackgroundProvider) SearchBackgrounds(c echo.Context) error {
|
||||
result, err := p.Search(s, search, page)
|
||||
if err != nil {
|
||||
_ = s.Rollback()
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "An error occurred: "+err.Error())
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "An error occurred: "+err.Error()).SetInternal(err)
|
||||
}
|
||||
|
||||
if err := s.Commit(); err != nil {
|
||||
_ = s.Rollback()
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "An error occurred: "+err.Error())
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "An error occurred: "+err.Error()).SetInternal(err)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, result)
|
||||
@ -98,12 +98,12 @@ func (bp *BackgroundProvider) SearchBackgrounds(c echo.Context) error {
|
||||
func (bp *BackgroundProvider) setBackgroundPreparations(s *xorm.Session, c echo.Context) (project *models.Project, auth web.Auth, err error) {
|
||||
auth, err = auth2.GetAuthFromClaims(c)
|
||||
if err != nil {
|
||||
return nil, nil, echo.NewHTTPError(http.StatusBadRequest, "Invalid auth token: "+err.Error())
|
||||
return nil, nil, echo.NewHTTPError(http.StatusBadRequest, "Invalid auth token: "+err.Error()).SetInternal(err)
|
||||
}
|
||||
|
||||
projectID, err := strconv.ParseInt(c.Param("project"), 10, 64)
|
||||
if err != nil {
|
||||
return nil, nil, echo.NewHTTPError(http.StatusBadRequest, "Invalid project ID: "+err.Error())
|
||||
return nil, nil, echo.NewHTTPError(http.StatusBadRequest, "Invalid project ID: "+err.Error()).SetInternal(err)
|
||||
}
|
||||
|
||||
// Check if the user has the right to change the project background
|
||||
@ -138,7 +138,7 @@ func (bp *BackgroundProvider) SetBackground(c echo.Context) error {
|
||||
err = c.Bind(image)
|
||||
if err != nil {
|
||||
_ = s.Rollback()
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided: "+err.Error())
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided: "+err.Error()).SetInternal(err)
|
||||
}
|
||||
|
||||
err = p.Set(s, image, project, auth)
|
||||
@ -274,12 +274,12 @@ func SaveBackgroundFile(s *xorm.Session, auth web.Auth, project *models.Project,
|
||||
func checkProjectBackgroundRights(s *xorm.Session, c echo.Context) (project *models.Project, auth web.Auth, err error) {
|
||||
auth, err = auth2.GetAuthFromClaims(c)
|
||||
if err != nil {
|
||||
return nil, auth, echo.NewHTTPError(http.StatusBadRequest, "Invalid auth token: "+err.Error())
|
||||
return nil, auth, echo.NewHTTPError(http.StatusBadRequest, "Invalid auth token: "+err.Error()).SetInternal(err)
|
||||
}
|
||||
|
||||
projectID, err := strconv.ParseInt(c.Param("project"), 10, 64)
|
||||
if err != nil {
|
||||
return nil, auth, echo.NewHTTPError(http.StatusBadRequest, "Invalid project ID: "+err.Error())
|
||||
return nil, auth, echo.NewHTTPError(http.StatusBadRequest, "Invalid project ID: "+err.Error()).SetInternal(err)
|
||||
}
|
||||
|
||||
// Check if a background for this project exists + Rights
|
||||
|
@ -83,7 +83,7 @@ func (mw *MigrationWeb) Migrate(c echo.Context) error {
|
||||
// Bind user request stuff
|
||||
err = c.Bind(ms)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided: "+err.Error())
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided: "+err.Error()).SetInternal(err)
|
||||
}
|
||||
|
||||
err = events.Dispatch(&MigrationRequestedEvent{
|
||||
|
@ -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 == "" {
|
||||
|
@ -51,8 +51,7 @@ func ProjectHandler(c echo.Context) error {
|
||||
|
||||
u, err := getBasicAuthUserFromContext(c)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return echo.ErrInternalServerError
|
||||
return echo.ErrInternalServerError.SetInternal(err)
|
||||
}
|
||||
|
||||
storage := &VikunjaCaldavProjectStorage{
|
||||
@ -69,8 +68,7 @@ func ProjectHandler(c echo.Context) error {
|
||||
if vtodo != "" && strings.HasPrefix(vtodo, `BEGIN:VCALENDAR`) {
|
||||
storage.task, err = caldav2.ParseTaskFromVTODO(vtodo)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return echo.ErrInternalServerError
|
||||
return echo.ErrInternalServerError.SetInternal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,8 +92,7 @@ func TaskHandler(c echo.Context) error {
|
||||
|
||||
u, err := getBasicAuthUserFromContext(c)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return echo.ErrInternalServerError
|
||||
return echo.ErrInternalServerError.SetInternal(err)
|
||||
}
|
||||
|
||||
// Get the task uid
|
||||
@ -117,8 +114,7 @@ func TaskHandler(c echo.Context) error {
|
||||
func PrincipalHandler(c echo.Context) error {
|
||||
u, err := getBasicAuthUserFromContext(c)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return echo.ErrInternalServerError
|
||||
return echo.ErrInternalServerError.SetInternal(err)
|
||||
}
|
||||
|
||||
storage := &VikunjaCaldavProjectStorage{
|
||||
@ -147,8 +143,7 @@ func PrincipalHandler(c echo.Context) error {
|
||||
func EntryHandler(c echo.Context) error {
|
||||
u, err := getBasicAuthUserFromContext(c)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return echo.ErrInternalServerError
|
||||
return echo.ErrInternalServerError.SetInternal(err)
|
||||
}
|
||||
|
||||
storage := &VikunjaCaldavProjectStorage{
|
||||
|
Loading…
x
Reference in New Issue
Block a user