Skip to content

v0.2.6

Compare
Choose a tag to compare
@suyuan32 suyuan32 released this 28 Feb 08:14

Docs

  • update readme
  • update functions doc
  • update change log

Feat

  • error handling
  • casbin redis watcher
  • casbin redis watcher

Fix

  • optimize ent transactions
  • menu directory bugs
  • remove member menu init data in core
  • post upper case

Refactor

  • optimize translator.

Pull Requests

  • Merge pull request #78 from suyuan32/feat-error-handling
  • Merge pull request #77 from suyuan32/feat-redis-watcher

更新注意

  • 本版本新增对 Ent 的错误处理,旧项目需要将 member 或者 new 项目中的 utils 复制到旧项目中并更改ent包路径为本地路径
package dberrorhandler

import (
	"github.com/zeromicro/go-zero/core/logx"

	"github.com/suyuan32/simple-admin-core/pkg/i18n"
	"github.com/suyuan32/simple-admin-core/pkg/msg/logmsg"
	"github.com/suyuan32/simple-admin-core/pkg/statuserr"

	"github.com/suyuan32/simple-admin-member-rpc/ent"   // 修改此处包为本地ent 路径, ent_tx 同理
)

// DefaultEntError returns errors dealing with default functions.
func DefaultEntError(err error, detail any) error {
	if err != nil {
		switch {
		case ent.IsNotFound(err):
			logx.Errorw(err.Error(), logx.Field("detail", detail))
			return statuserr.NewInvalidArgumentError(i18n.TargetNotFound)
		case ent.IsConstraintError(err):
			logx.Errorw(err.Error(), logx.Field("detail", detail))
			return statuserr.NewInvalidArgumentError(i18n.ConstraintError)
		case ent.IsValidationError(err):
			logx.Errorw(err.Error(), logx.Field("detail", detail))
			return statuserr.NewInvalidArgumentError(i18n.ValidationError)
		case ent.IsNotSingular(err):
			logx.Errorw(err.Error(), logx.Field("detail", detail))
			return statuserr.NewInvalidArgumentError(i18n.NotSingularError)
		default:
			logx.Errorw(logmsg.DatabaseError, logx.Field("detail", err.Error()))
			return statuserr.NewInternalError(i18n.DatabaseError)
		}
	}
	return err
}
  • 项目默认添加事务支持 ent_tx
  • 新增 casbin redis watcher 监控权限变化

What's Changed

Full Changelog: v0.2.5...v0.2.6