Add GraphQL rate limit error detection with distinct return type for callers #2111
+485
−13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GitHub's GraphQL API returns rate limit errors in the response body (
errors[].type === 'RATE_LIMIT'), but we only checked HTTP headers. This caused silent failures when rate limits were hit.Changes
Type system
GraphQLErrorandGraphQLResponse<T>interfaces for proper response typingisRateLimitError()helper to detect rate limit errors in response bodyRATE_LIMITconstant for distinct rate limit error handlingAPI functions
makeGitHubGraphQLRequest<T>: Now returns typedGraphQLResponse<T>, detects and logs rate limit errors from response body, sends telemetrymakeSearchGraphQLRequest: ReturnsRATE_LIMITconstant on rate limit (instead of empty array), allowing callers to distinguish rate limits from empty resultsgetPullRequestFromGlobalId: ReturnsRATE_LIMITconstant on rate limit, allowing callers to distinguish fromnull(not found)addPullRequestCommentGraphQLRequest: ReturnsRATE_LIMITconstant on rate limit, allowing callers to distinguish fromnull(failure)Return types
makeSearchGraphQLRequest:Promise<PullRequestSearchItem[] | typeof RATE_LIMIT>getPullRequestFromGlobalId:Promise<PullRequestSearchItem | null | typeof RATE_LIMIT>addPullRequestCommentGraphQLRequest:Promise<PullRequestComment | null | typeof RATE_LIMIT>Example usage
Callers can now explicitly check for rate limits using
result === RATE_LIMIT, enabling distinct handling separate from null/empty responses.Created from VS Code.
Original prompt
Created from VS Code.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.