Skip to content

Commit

Permalink
fix: refacotor method name error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Manish Dangi committed Oct 15, 2024
1 parent 9774d00 commit 2092df6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/notification/router_receiver_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *RouterReceiverService) PrepareMetaMessages(ctx context.Context, n Notif
rcvs, userConfigs, err = s.handleConfigCase(ctx, n.ReceiverSelectors)
} else {
// Handle case when only receiver IDs are provided
rcvs, err = s.handleIDOnlyCase(ctx, n.ReceiverSelectors)
rcvs, err = s.handleNonConfigCase(ctx, n.ReceiverSelectors)
}

if err != nil {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (s *RouterReceiverService) handleConfigCase(ctx context.Context, selectors
return rcvs, userConfigs, nil
}

func (s *RouterReceiverService) handleIDOnlyCase(ctx context.Context, selectors []map[string]any) ([]receiver.Receiver, error) {
func (s *RouterReceiverService) handleNonConfigCase(ctx context.Context, selectors []map[string]any) ([]receiver.Receiver, error) {
convertedSelectors := make([]map[string]string, len(selectors))
for i, selector := range selectors {
convertedSelectors[i] = make(map[string]string)
Expand Down
6 changes: 4 additions & 2 deletions internal/api/v1beta1/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ func (s *GRPCServer) PostNotification(ctx context.Context, req *sirenv1beta1.Pos

idempotencyKey := api.GetHeaderString(ctx, s.headers.IdempotencyKey)
if idempotencyKey != "" {
if notificationID, err := s.notificationService.CheckIdempotency(ctx, idempotencyScope, idempotencyKey); err == nil {
if notificationID, err := s.notificationService.CheckIdempotency(ctx, idempotencyScope, idempotencyKey); notificationID != "" {
return &sirenv1beta1.PostNotificationResponse{
NotificationId: notificationID,
}, nil
} else if !errors.Is(err, errors.ErrNotFound) {
} else if errors.Is(err, errors.ErrNotFound) {
s.logger.Debug("no idempotency found with detail", "scope", idempotencyScope, "key", idempotencyKey)
} else {
return nil, api.GenerateRPCErr(s.logger, fmt.Errorf("error when checking idempotency: %w", err))
}
}
Expand Down

0 comments on commit 2092df6

Please sign in to comment.