Skip to content

Conversation

Copy link

Copilot AI commented Feb 2, 2026

User reported 502 errors from axios causing complete failure when fetching starred gists. The code had no retry logic and used Promise.all, causing any single failed request to abort the entire batch.

Changes

Dependency Updates

Retry Logic

  • Added lib/axiosWithRetry.js utility with exponential backoff (1s, 2s, 4s)
  • Retries transient failures: 5xx, 429, network errors
  • Fails fast on 4xx client errors (except 429)

Fault Tolerance

  • Replaced Promise.all with Promise.allSettled in batch operations
  • Individual gist failures logged but don't stop processing
  • Applied consistently across starredGists.js, gists.js, starredRepositories.js

Example

Before:

await Promise.all(
  response.data.map(async (gist) => {
    const details = await axios({ url: gist.url, ... }); // Any failure aborts all
    // process gist
  })
);

After:

const results = await Promise.allSettled(
  response.data.map(async (gist) => {
    try {
      const details = await axiosWithRetry({ url: gist.url, ... }); // Retries 502s
      return { success: true, data: details.data };
    } catch (error) {
      console.error(`Failed to fetch gist ${gist.id}: ${error.response?.status} - ${error.message}`);
      return { success: false, id: gist.id };
    }
  })
);

for (const result of results) {
  if (result.status === 'fulfilled' && result.value.success) {
    // process successful fetches only
  }
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/
    • Triggering command: /usr/local/bin/node node test-retry.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>502 error from axios</issue_title>
<issue_description>Wondering if this still works.

AxiosError: Request failed with status code 502
    at settle (/Users/maxpleaner/Desktop/Code2/github-takeout/node_modules/axios/dist/node/axios.cjs:1966:12)
    at IncomingMessage.handleStreamEnd (/Users/maxpleaner/Desktop/Code2/github-takeout/node_modules/axios/dist/node/axios.cjs:3065:11)
    at IncomingMessage.emit (node:events:520:35)
    at endReadableNT (node:internal/streams/readable:1701:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:89:21)
    at Axios.request (/Users/maxpleaner/Desktop/Code2/github-takeout/node_modules/axios/dist/node/axios.cjs:3876:41)
    at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    at async /Users/maxpleaner/Desktop/Code2/github-takeout/lib/starredGists.js:108:29
    at async Promise.all (index 14)
    at async processStarredGists (/Users/maxpleaner/Desktop/Code2/github-takeout/lib/starredGists.js:106:5)
    at async processAllStarredGists (/Users/maxpleaner/Desktop/Code2/github-takeout/lib/starredGists.js:241:9) {

Are there some specific permissions we need for our token?</issue_description>

<agent_instructions>look at the dependencies, update them as needed. look at the axios error listed in this issue and fix it</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits February 2, 2026 01:23
Co-authored-by: devarda <50584220+devarda@users.noreply.github.com>
Co-authored-by: devarda <50584220+devarda@users.noreply.github.com>
Co-authored-by: devarda <50584220+devarda@users.noreply.github.com>
Co-authored-by: devarda <50584220+devarda@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix 502 error from axios requests Fix 502 errors with retry logic and fault-tolerant batch processing Feb 2, 2026
Copilot AI requested a review from devarda February 2, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

502 error from axios

2 participants