Skip to content

Commit dd5d5a8

Browse files
committed
fix(errors): improve rate limit error messages for agents
Detect RateLimitError and AbuseRateLimitError in NewGitHubAPIErrorResponse and return clear, actionable messages with retry duration instead of burying the information in raw HTTP strings. Fixes #2385
1 parent 7b962fd commit dd5d5a8

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

pkg/errors/error.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package errors
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/http"
8+
"time"
79

810
"github.com/github/github-mcp-server/pkg/utils"
911
"github.com/google/go-github/v82/github"
@@ -159,6 +161,25 @@ func NewGitHubAPIErrorResponse(ctx context.Context, message string, resp *github
159161
if ctx != nil {
160162
_, _ = addGitHubAPIErrorToContext(ctx, apiErr) // Explicitly ignore error for graceful handling
161163
}
164+
165+
// Handle rate limit errors with clear, actionable messages
166+
var rateLimitErr *github.RateLimitError
167+
if errors.As(err, &rateLimitErr) {
168+
retryIn := time.Until(rateLimitErr.Rate.Reset.Time).Round(time.Second)
169+
return utils.NewToolResultError(fmt.Sprintf(
170+
"%s: GitHub API rate limit exceeded. Retry after %v.", message, retryIn))
171+
}
172+
173+
var abuseErr *github.AbuseRateLimitError
174+
if errors.As(err, &abuseErr) {
175+
if abuseErr.RetryAfter != nil {
176+
return utils.NewToolResultError(fmt.Sprintf(
177+
"%s: GitHub secondary rate limit exceeded. Retry after %v.", message, abuseErr.RetryAfter.Round(time.Second)))
178+
}
179+
return utils.NewToolResultError(fmt.Sprintf(
180+
"%s: GitHub secondary rate limit exceeded. Wait before retrying.", message))
181+
}
182+
162183
return utils.NewToolResultErrorFromErr(message, err)
163184
}
164185

0 commit comments

Comments
 (0)