Add error code handling

This commit is contained in:
Zoltán Papp
2025-09-25 12:46:05 +02:00
parent 4d46adbb68
commit 71733dff3e
4 changed files with 35 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package client
import (
"context"
"errors"
"fmt"
"io"
"sync"
@@ -22,6 +23,10 @@ import (
"github.com/netbirdio/netbird/shared/signal/proto"
)
var (
ErrPeerNotAvailable = errors.New("peer not available")
)
// ConnStateNotifier is a wrapper interface of the status recorder
type ConnStateNotifier interface {
MarkSignalDisconnected(error)
@@ -410,6 +415,17 @@ func (c *GrpcClient) SendWithDeliveryCheck(msg *proto.Message) error {
defer cancel()
_, err = c.realClient.SendWithDeliveryCheck(ctx, encryptedMessage)
if err != nil {
if st, ok := status.FromError(err); ok {
switch st.Code() {
case codes.NotFound:
return ErrPeerNotAvailable
default:
return fmt.Errorf("grpc error %s: %w", st.Code(), err)
}
}
return err // Not a gRPC status error
}
return err
}