Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode

This commit is contained in:
wangchuxiao 2023-03-16 19:02:21 +08:00
commit d2cd3618e0
3 changed files with 7 additions and 7 deletions

View File

@ -17,12 +17,12 @@ func Call[A, B, C any](
var req A var req A
if err := c.BindJSON(&req); err != nil { if err := c.BindJSON(&req); err != nil {
log.ZWarn(c, "gin bind json error", err, "req", req) log.ZWarn(c, "gin bind json error", err, "req", req)
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error())) // 参数错误 apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap()) // 参数错误
return return
} }
if check, ok := any(&req).(interface{ Check() error }); ok { if check, ok := any(&req).(interface{ Check() error }); ok {
if err := check.Check(); err != nil { if err := check.Check(); err != nil {
log.ZWarn(c, "custom check error", err, "req", req) log.ZWarn(c, "custom check error", err, "req", req)
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error())) // 参数校验失败 apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error())) // 参数校验失败
return return
} }

View File

@ -41,7 +41,7 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry, rdb redis.Universal
userRouterGroupChildToken.POST("/account_check", u.AccountCheck) // todo userRouterGroupChildToken.POST("/account_check", u.AccountCheck) // todo
userRouterGroupChildToken.POST("/get_users", u.GetUsers) userRouterGroupChildToken.POST("/get_users", u.GetUsers)
} }
////friend routing group //friend routing group
friendRouterGroup := r.Group("/friend") friendRouterGroup := r.Group("/friend")
{ {
f := NewFriend(zk) f := NewFriend(zk)

View File

@ -35,7 +35,7 @@ func rpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
log.ZError(ctx, "rpc panic", nil, "FullMethod", info.FullMethod, "type:", fmt.Sprintf("%T", r), "panic:", r) log.ZError(ctx, "rpc panic", nil, "FullMethod", info.FullMethod, "type:", fmt.Sprintf("%T", r), "panic:", r)
fmt.Println("stack info:", string(debug.Stack())) fmt.Println("stack info:", string(debug.Stack()))
pc, file, line, ok := runtime.Caller(4) pc, file, line, ok := runtime.Caller(4)
if ok { if !ok {
panic("get runtime.Caller failed") panic("get runtime.Caller failed")
} }
errInfo := &errinfo.ErrorInfo{ errInfo := &errinfo.ErrorInfo{
@ -45,9 +45,9 @@ func rpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
Cause: fmt.Sprintf("%s", r), Cause: fmt.Sprintf("%s", r),
Warp: nil, Warp: nil,
} }
sta, err := status.New(codes.Code(errs.ErrInternalServer.Code()), errs.ErrInternalServer.Msg()).WithDetails(errInfo) sta, err_ := status.New(codes.Code(errs.ErrInternalServer.Code()), errs.ErrInternalServer.Msg()).WithDetails(errInfo)
if err != nil { if err_ != nil {
panic(err) panic(err_)
} }
err = sta.Err() err = sta.Err()
} }