Skip to content

Commit d549bd9

Browse files
docs-botCopilot
andauthored
fix: use duck-typing in octoSecondaryRatelimitRetry to fix instanceof check (#61169)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent da5f09f commit d549bd9

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/workflows/secondary-ratelimit-retry.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { RequestError } from '@octokit/request-error'
2-
31
const DEFAULT_SLEEPTIME = parseInt(process.env.SECONDARY_RATELIMIT_RETRY_SLEEPTIME || '30000', 10)
42
const DEFAULT_ATTEMPTS = parseInt(process.env.SECONDARY_RATELIMIT_RETRY_ATTEMPTS || '5', 10)
53

@@ -16,9 +14,14 @@ export async function octoSecondaryRatelimitRetry<T>(
1614
try {
1715
return await fn()
1816
} catch (error) {
17+
// Use duck-typing instead of `instanceof RequestError` because octokit
18+
// bundles its own copy of @octokit/request-error in dist-bundle/index.js,
19+
// so the class reference differs from the top-level package and instanceof
20+
// always returns false across the module boundary.
1921
if (
20-
error instanceof RequestError &&
21-
error.status === 403 &&
22+
error instanceof Error &&
23+
'status' in error &&
24+
(error as { status: number }).status === 403 &&
2225
/You have exceeded a secondary rate limit/.test(error.message)
2326
) {
2427
if (tries < attempts) {

0 commit comments

Comments
 (0)