groupServer

This commit is contained in:
withchao 2023-05-18 17:08:48 +08:00
parent c53daa76f2
commit fb429c70c4

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"math" "math"
"runtime" "runtime"
"runtime/debug"
"strings" "strings"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
@ -30,28 +29,28 @@ func rpcString(v interface{}) string {
} }
func RpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { func RpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
defer func() { //defer func() {
if r := recover(); r != nil { // if r := recover(); r != nil {
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.Printf("panic: %+v\nstack info: %s\n", r, string(debug.Stack())) // fmt.Printf("panic: %+v\nstack info: %s\n", r, 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{
Path: file, // Path: file,
Line: uint32(line), // Line: uint32(line),
Name: runtime.FuncForPC(pc).Name(), // Name: runtime.FuncForPC(pc).Name(),
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()
} // }
}() //}()
funcName := info.FullMethod funcName := info.FullMethod
md, ok := metadata.FromIncomingContext(ctx) md, ok := metadata.FromIncomingContext(ctx)
if !ok { if !ok {