You've already forked focalboard
mirror of
https://github.com/mattermost/focalboard.git
synced 2025-07-12 23:50:27 +02:00
Refactor error usage from the store level up and add API helpers (#3792)
* Refactor error usage from the store level up and add API helpers * Complete API tests * Fix merge errorResponse calls * Remove ensure helpers to allow for custom messages on permission errors * Fix bad import and call * Remove bad user check on auth that was added as part of the main merge * Fix empty list test * Replace deprecated proxy calls to ioutil.ReadAll with io.ReadAll * Add information to the NotFound errors * Add context to all remaining errors and address review comments * Fix linter * Adapt the new card API endpoints to the error refactor * Remove almost all customErrorResponse calls * Add request entity too large to errorResponse and remove customErrorResponse * Fix linter
This commit is contained in:
committed by
GitHub
parent
ed655ac996
commit
08c0b7a2fd
@ -13,11 +13,17 @@ const (
|
||||
MinimumPasswordLength = 8
|
||||
)
|
||||
|
||||
type AuthParamError struct {
|
||||
func NewErrAuthParam(msg string) *ErrAuthParam {
|
||||
return &ErrAuthParam{
|
||||
msg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
type ErrAuthParam struct {
|
||||
msg string
|
||||
}
|
||||
|
||||
func (pe AuthParamError) Error() string {
|
||||
func (pe *ErrAuthParam) Error() string {
|
||||
return pe.msg
|
||||
}
|
||||
|
||||
@ -84,16 +90,16 @@ type RegisterRequest struct {
|
||||
|
||||
func (rd *RegisterRequest) IsValid() error {
|
||||
if strings.TrimSpace(rd.Username) == "" {
|
||||
return AuthParamError{"username is required"}
|
||||
return NewErrAuthParam("username is required")
|
||||
}
|
||||
if strings.TrimSpace(rd.Email) == "" {
|
||||
return AuthParamError{"email is required"}
|
||||
return NewErrAuthParam("email is required")
|
||||
}
|
||||
if !auth.IsEmailValid(rd.Email) {
|
||||
return AuthParamError{"invalid email format"}
|
||||
return NewErrAuthParam("invalid email format")
|
||||
}
|
||||
if rd.Password == "" {
|
||||
return AuthParamError{"password is required"}
|
||||
return NewErrAuthParam("password is required")
|
||||
}
|
||||
return isValidPassword(rd.Password)
|
||||
}
|
||||
@ -113,17 +119,17 @@ type ChangePasswordRequest struct {
|
||||
// IsValid validates a password change request.
|
||||
func (rd *ChangePasswordRequest) IsValid() error {
|
||||
if rd.OldPassword == "" {
|
||||
return AuthParamError{"old password is required"}
|
||||
return NewErrAuthParam("old password is required")
|
||||
}
|
||||
if rd.NewPassword == "" {
|
||||
return AuthParamError{"new password is required"}
|
||||
return NewErrAuthParam("new password is required")
|
||||
}
|
||||
return isValidPassword(rd.NewPassword)
|
||||
}
|
||||
|
||||
func isValidPassword(password string) error {
|
||||
if len(password) < MinimumPasswordLength {
|
||||
return AuthParamError{fmt.Sprintf("password must be at least %d characters", MinimumPasswordLength)}
|
||||
return NewErrAuthParam(fmt.Sprintf("password must be at least %d characters", MinimumPasswordLength))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user