feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
This commit is contained in:
48
pkg/errors/errors.go
Normal file
48
pkg/errors/errors.go
Normal file
@@ -0,0 +1,48 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user