优化错误提示

This commit is contained in:
刘祥超
2023-06-16 08:17:00 +08:00
parent 2aceb4fb4d
commit eee902abec
2 changed files with 10 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ import (
"github.com/iwind/gosock/pkg/gosock"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/status"
"gopkg.in/yaml.v3"
"log"
"net"
@@ -832,7 +833,12 @@ func (this *APINode) unaryInterceptor(ctx context.Context, req any, info *grpc.U
}
result, err := handler(ctx, req)
if err != nil {
err = errors.New("'" + info.FullMethod + "()' says: " + err.Error())
statusErr, ok := status.FromError(err)
if ok {
err = status.Error(statusErr.Code(), "'" + info.FullMethod + "()' says: " + err.Error())
} else {
err = errors.New("'" + info.FullMethod + "()' says: " + err.Error())
}
}
return result, err
}