Skip to content

Commit

Permalink
enhance error handling in fanout.go to include 'deadline exceeded' as…
Browse files Browse the repository at this point in the history
… a retryable error and update test cases to reflect new response structure
  • Loading branch information
KingPin committed Mar 1, 2025
1 parent f37f17d commit 9328672
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions fanout.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,14 @@ func isRetryableError(err error) bool {
return false
}

errMsg := strings.ToLower(err.Error())

// Check specific error types that should be retried
if strings.Contains(err.Error(), "connection refused") ||
strings.Contains(err.Error(), "timeout") ||
strings.Contains(err.Error(), "connection reset") ||
strings.Contains(err.Error(), "no such host") {
if strings.Contains(errMsg, "connection refused") ||
strings.Contains(errMsg, "timeout") ||
strings.Contains(errMsg, "deadline exceeded") || // Added this line
strings.Contains(errMsg, "connection reset") ||
strings.Contains(errMsg, "no such host") {
return true
}

Expand Down
7 changes: 4 additions & 3 deletions fanout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ func TestWriteJSON(t *testing.T) {
expected: `{"key":"value"}`,
},
{
name: "Response object",
data: Response{Target: "http://example.com", Status: 200, Body: "OK"},
expected: `{"target":"http://example.com","status":200,"body":"OK"}`,
name: "Response object",
data: Response{Target: "http://example.com", Status: 200, Body: "OK"},
// Updated to include latency and attempts fields
expected: `{"target":"http://example.com","status":200,"body":"OK","latency":0,"attempts":0}`,
},
}

Expand Down

0 comments on commit 9328672

Please sign in to comment.