49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
|
|
package errors
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
)
|
||
|
|
|
||
|
|
var (
|
||
|
|
// 用户相关错误
|
||
|
|
ErrUserNotFound = errors.New("用户不存在")
|
||
|
|
ErrUsernameExists = errors.New("用户名已存在")
|
||
|
|
ErrEmailExists = errors.New("邮箱已存在")
|
||
|
|
ErrPhoneExists = errors.New("手机号已存在")
|
||
|
|
ErrInvalidCredentials = errors.New("用户名或密码错误")
|
||
|
|
ErrAccountLocked = errors.New("账号已被锁定")
|
||
|
|
ErrAccountDisabled = errors.New("账号已被禁用")
|
||
|
|
ErrInvalidOldPassword = errors.New("原密码错误")
|
||
|
|
|
||
|
|
// 角色相关错误
|
||
|
|
ErrRoleNotFound = errors.New("角色不存在")
|
||
|
|
ErrRoleCodeExists = errors.New("角色代码已存在")
|
||
|
|
ErrCannotModifySystemRole = errors.New("不能修改系统角色")
|
||
|
|
ErrCannotDeleteSystemRole = errors.New("不能删除系统角色")
|
||
|
|
ErrRoleInUse = errors.New("角色正在使用中")
|
||
|
|
|
||
|
|
// 权限相关错误
|
||
|
|
ErrPermissionNotFound = errors.New("权限不存在")
|
||
|
|
ErrPermissionCodeExists = errors.New("权限代码已存在")
|
||
|
|
|
||
|
|
// 通用错误
|
||
|
|
ErrInvalidParams = errors.New("参数错误")
|
||
|
|
ErrUnauthorized = errors.New("未授权")
|
||
|
|
ErrForbidden = errors.New("无权限")
|
||
|
|
ErrInternalServerError = errors.New("服务器内部错误")
|
||
|
|
)
|
||
|
|
|
||
|
|
// NewError 创建新错误
|
||
|
|
func NewError(msg string) error {
|
||
|
|
return errors.New(msg)
|
||
|
|
}
|
||
|
|
|
||
|
|
// WrapError 包装错误
|
||
|
|
func WrapError(err error, msg string) error {
|
||
|
|
if err == nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
return fmt.Errorf("%s: %w", msg, err)
|
||
|
|
}
|