Skip to content

Commit e378965

Browse files
committed
fix circuit breaker error
1 parent 548782f commit e378965

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

internal/service/broadcast/errors.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ type BroadcastError struct {
4141

4242
// Error implements the error interface
4343
func (e *BroadcastError) Error() string {
44+
if e.Err != nil {
45+
if e.TaskID != "" {
46+
return fmt.Sprintf("[%s] %s (task: %s): %v", e.Code, e.Message, e.TaskID, e.Err)
47+
}
48+
return fmt.Sprintf("[%s] %s: %v", e.Code, e.Message, e.Err)
49+
}
50+
// Fallback when Err is nil
4451
if e.TaskID != "" {
45-
return fmt.Sprintf("[%s] %s (task: %s): %v", e.Code, e.Message, e.TaskID, e.Err)
52+
return fmt.Sprintf("[%s] %s (task: %s)", e.Code, e.Message, e.TaskID)
4653
}
47-
return fmt.Sprintf("[%s] %s: %v", e.Code, e.Message, e.Err)
54+
return fmt.Sprintf("[%s] %s", e.Code, e.Message)
4855
}
4956

5057
// Unwrap returns the underlying error

internal/service/broadcast/message_sender.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (s *messageSender) SendToRecipient(ctx context.Context, workspaceID string,
210210
logFields["last_error"] = lastError.Error()
211211
}
212212
s.logger.WithFields(logFields).Warn("Circuit breaker open, skipping send")
213-
return NewBroadcastError(ErrCodeCircuitOpen, fmt.Sprintf("circuit breaker is open: %v", lastError), true, nil)
213+
return NewBroadcastError(ErrCodeCircuitOpen, "circuit breaker is open", true, lastError)
214214
}
215215

216216
// Apply rate limiting
@@ -395,7 +395,7 @@ func (s *messageSender) SendBatch(ctx context.Context, workspaceID string, integ
395395
logFields["last_error"] = lastError.Error()
396396
}
397397
s.logger.WithFields(logFields).Warn("Circuit breaker open, skipping batch")
398-
return 0, 0, NewBroadcastError(ErrCodeCircuitOpen, fmt.Sprintf("circuit breaker is open: %v", lastError), true, nil)
398+
return 0, 0, NewBroadcastError(ErrCodeCircuitOpen, "circuit breaker is open", true, lastError)
399399
}
400400

401401
// Get the broadcast to determine variations and templates

0 commit comments

Comments
 (0)