54 lines
3.0 KiB
Go
54 lines
3.0 KiB
Go
package errs
|
|
|
|
import "net/http"
|
|
|
|
type AppError struct {
|
|
HTTPCode int
|
|
Msg string
|
|
}
|
|
|
|
func (e *AppError) Error() string {
|
|
return e.Msg
|
|
}
|
|
|
|
func New(httpCode int, msg string) *AppError {
|
|
return &AppError{
|
|
HTTPCode: httpCode,
|
|
Msg: msg,
|
|
}
|
|
}
|
|
|
|
var (
|
|
ErrInvalidCredentials = New(http.StatusUnauthorized, "用户名或密码错误")
|
|
ErrUserDisabled = New(http.StatusForbidden, "用户已被禁用")
|
|
ErrUnauthenticated = New(http.StatusUnauthorized, "用户未登录或登录已失效")
|
|
ErrUnauthorized = New(http.StatusUnauthorized, "认证失败:无法获取当前用户信息")
|
|
ErrInvalidToken = New(http.StatusUnauthorized, "登录凭证无效")
|
|
ErrInvalidTokenClaims = New(http.StatusUnauthorized, "登录凭证解析失败")
|
|
ErrInvalidRefreshToken = New(http.StatusBadRequest, "invalid_grant")
|
|
ErrExpiredRefreshToken = New(http.StatusBadRequest, "invalid_grant")
|
|
ErrUserNotFound = New(http.StatusNotFound, "用户数据不存在")
|
|
ErrCategoryNotFound = New(http.StatusNotFound, "分类数据不存在")
|
|
ErrTagNotFound = New(http.StatusNotFound, "标签数据不存在")
|
|
ErrApiNotFound = New(http.StatusNotFound, "接口数据不存在")
|
|
ErrPostNotFound = New(http.StatusNotFound, "文章数据不存在")
|
|
ErrMenuNotFound = New(http.StatusNotFound, "菜单数据不存在")
|
|
ErrRoleNotFound = New(http.StatusNotFound, "角色数据不存在")
|
|
ErrCannotDeleteSuperAdmin = New(http.StatusForbidden, "超级管理员账号无法被删除")
|
|
ErrSlugRequired = New(http.StatusBadRequest, "slug不能为空")
|
|
ErrIDRequired = New(http.StatusBadRequest, "id不能为空")
|
|
ErrPermissionDenied = New(http.StatusForbidden, "没有权限访问该资源")
|
|
ErrInvalidID = New(http.StatusBadRequest, "id非法请检查传入的id")
|
|
ErrEmptyBody = New(http.StatusBadRequest, "请求内容(body)不能为空")
|
|
ErrInvalidJSON = New(http.StatusBadRequest, "请求数据格式错误")
|
|
ErrAccountAlreadyExists = New(http.StatusBadRequest, "账号已存在")
|
|
ErrCodeAlreadyExists = New(http.StatusBadRequest, "角色编码不允许重复")
|
|
ErrSlugAlreadyExists = New(http.StatusBadRequest, "slug不允许重复")
|
|
ErrPermissionCodeAlreadyExists = New(http.StatusBadRequest, "权限编码不允许重复")
|
|
ErrCategoryCodeAlreadyExists = New(http.StatusBadRequest, "分类编码不允许重复")
|
|
ErrTagCodeAlreadyExists = New(http.StatusBadRequest, "标签编码不允许重复")
|
|
ErrMenusPathUniqueIdx = New(http.StatusBadRequest, "菜单路径不允许重复")
|
|
ErrApiMethodPathAlreadyExists = New(http.StatusBadRequest, "接口方法(method)路径(path)不允许重复")
|
|
ErrInvalidApiPath = New(http.StatusBadRequest, "接口路径格式不正确,必须以/开头,参数段需为{name}格式")
|
|
)
|