优化错误提示

This commit is contained in:
刘祥超
2021-11-10 21:51:56 +08:00
parent f8160e35b9
commit 8210ece2b7
15 changed files with 112 additions and 31 deletions

View File

@@ -2,12 +2,15 @@ package rpc
import (
"github.com/TeaOSLab/EdgeNode/internal/configs"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"sync"
)
var sharedRPC *RPCClient = nil
var locker = &sync.Mutex{}
// SharedRPC RPC对象
func SharedRPC() (*RPCClient, error) {
locker.Lock()
defer locker.Unlock()
@@ -28,3 +31,18 @@ func SharedRPC() (*RPCClient, error) {
sharedRPC = client
return sharedRPC, nil
}
// IsConnError 是否为连接错误
func IsConnError(err error) bool {
if err == nil {
return false
}
// 检查是否为连接错误
statusErr, ok := status.FromError(err)
if ok {
return statusErr.Code() == codes.Unavailable
}
return false
}