feat(gitea): add retry logic for 5xx errors #69

Merged
aweiker merged 7 commits from issue-68 into main 2026-05-11 12:59:50 +00:00
Showing only changes of commit 1b38e6ad00 - Show all commits
+7 -5
View File
35
@@ -374,19 +374,21 @@ func (c *Client) doGet(ctx context.Context, reqURL string) ([]byte, error) {
resp, err := c.http.Do(req)
if err != nil {
// Check if this is a temporary/transient network error worth retrying.
// We only retry if there are attempts remaining.
// Always capture the error for consistent return at loop end.
// This ensures both network errors and HTTP 5xx return lastErr.
lastErr = err
// Only retry temporary network errors when attempts remain.
if attempt < maxAttempts-1 && isTemporaryNetError(err) {
slog.Warn("temporary network error, will retry",
"attempt", attempt+1,
"url", redactURL(reqURL),
"error", err)
lastErr = err
continue
}
return nil, err
// Non-retryable network error or final attempt exhausted.
return nil, lastErr
}
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
body, err := io.ReadAll(resp.Body)
resp.Body.Close()
1