error.go 831 B

12345678910111213141516171819202122232425
  1. package global
  2. import (
  3. "errors"
  4. "github.com/go-sql-driver/mysql"
  5. )
  6. var (
  7. GetFailedErr = errors.New("查询失败")
  8. CreateFailedErr = errors.New("添加失败")
  9. UpdateFailedErr = errors.New("更新失败")
  10. DeleteFailedErr = errors.New("删除失败")
  11. GetNotFoundErr = errors.New("数据不存在")
  12. GetNotFoundOrNoPermissionErr = errors.New("数据不存在或无权查看该数据")
  13. UpdateNotFoundOrNoPermissionErr = errors.New("数据不存在或无权修改该数据")
  14. DeleteNotFoundOrNoPermissionErr = errors.New("数据不存在或无权删除该数据")
  15. )
  16. func IsUniqueIndexErr(err error) bool {
  17. uniqueErr := &mysql.MySQLError{}
  18. if ok := errors.As(err, &uniqueErr); ok {
  19. return uniqueErr.Number == 1062
  20. }
  21. return false
  22. }