test-errcode
wangchuxiao 2 years ago
parent f7cf573ba8
commit 2d6c837f0d

@ -9,6 +9,7 @@ import (
http2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http" http2 "github.com/OpenIMSDK/Open-IM-Server/pkg/common/http"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils/splitter" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils/splitter"
"github.com/go-redis/redis/v8" "github.com/go-redis/redis/v8"
@ -23,8 +24,8 @@ import (
) )
var ( var (
TokenExpireError = errors.New("token expire") ErrTokenExpire = errors.New("token expire")
UserIDEmptyError = errors.New("userIDs is empty") ErrUserIDEmpty = errors.New("userIDs is empty")
) )
const ( const (
@ -52,7 +53,7 @@ func NewClient(cache cache.MsgModel) *Client {
func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error { func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error {
token, err := g.cache.GetGetuiToken(ctx) token, err := g.cache.GetGetuiToken(ctx)
if err != nil { if err != nil {
if err == redis.Nil { if errs.Unwrap(err) == redis.Nil {
log.ZInfo(ctx, "getui token not exist in redis") log.ZInfo(ctx, "getui token not exist in redis")
token, err = g.getTokenAndSave2Redis(ctx) token, err = g.getTokenAndSave2Redis(ctx)
if err != nil { if err != nil {
@ -86,10 +87,10 @@ func (g *Client) Push(ctx context.Context, userIDs []string, title, content stri
} else if len(userIDs) == 1 { } else if len(userIDs) == 1 {
err = g.singlePush(ctx, token, userIDs[0], pushReq) err = g.singlePush(ctx, token, userIDs[0], pushReq)
} else { } else {
return UserIDEmptyError return ErrUserIDEmpty
} }
switch err { switch err {
case TokenExpireError: case ErrTokenExpire:
token, err = g.getTokenAndSave2Redis(ctx) token, err = g.getTokenAndSave2Redis(ctx)
} }
return err return err

Loading…
Cancel
Save