From 4902161f0aa0bf6f213df2119441a22de05a0192 Mon Sep 17 00:00:00 2001 From: Vadim Inshakov Date: Tue, 19 Dec 2023 00:38:43 +0500 Subject: [PATCH] fix err handling --- core/coordinator/coordinator.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/coordinator/coordinator.go b/core/coordinator/coordinator.go index 9829208..948a279 100644 --- a/core/coordinator/coordinator.go +++ b/core/coordinator/coordinator.go @@ -85,6 +85,13 @@ func (c *coordinatorImpl) Broadcast(ctx context.Context, req dto.BroadcastReques // commit log.Infof("commit %s", req.Key) if err := c.commit(ctx); err != nil { + s, ok := status.FromError(err) + if !ok { + return &dto.BroadcastResponse{Type: dto.ResponseTypeNack}, fmt.Errorf("failed to extract grpc status code from err: %s", err) + } + if s.Code() == codes.AlreadyExists { + return &dto.BroadcastResponse{Type: dto.ResponseTypeNack}, nil + } return &dto.BroadcastResponse{Type: dto.ResponseTypeNack}, errors.Wrap(err, "failed to send commit") }