Skip to content

Commit b7abe8b

Browse files
committed
feat: replace the kratos error by own
1 parent 5418788 commit b7abe8b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

gmicro/server/rpcserver/selector/node/ewma/node.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"sync/atomic"
99
"time"
1010

11+
"google.golang.org/grpc/codes"
12+
1113
"github.com/CoderI421/gframework/gmicro/server/rpcserver/selector"
1214

13-
"github.com/go-kratos/kratos/v2/errors"
15+
"github.com/CoderI421/gframework/pkg/errors"
1416
)
1517

1618
const (
@@ -164,7 +166,7 @@ func (n *Node) Pick() selector.DoneFunc {
164166
success = 0
165167
}
166168
} else if errors.Is(context.DeadlineExceeded, di.Err) || errors.Is(context.Canceled, di.Err) ||
167-
errors.IsServiceUnavailable(di.Err) || errors.IsGatewayTimeout(di.Err) {
169+
errors.FromGrpcErrorCode(di.Err) == int(codes.Unavailable) || errors.FromGrpcErrorCode(di.Err) == int(codes.DeadlineExceeded) {
168170
success = 0
169171
}
170172
}

pkg/errors/errors.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ func FromGrpcError(e error) error {
159159
}
160160
}
161161

162+
func FromGrpcErrorCode(e error) int {
163+
if e == nil {
164+
return 100002
165+
}
166+
167+
st, ok := status.FromError(e)
168+
if !ok {
169+
return 100002
170+
}
171+
172+
return int(st.Code())
173+
}
174+
162175
func ToGrpcError(e error) error {
163176
if e == nil {
164177
return e

0 commit comments

Comments
 (0)