Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

430
Views
Random Fetch Error when I restart my program

I'm looping through this array of names and using each name to change the end point in the URI. The data from the end points is then stored in a Promise.all() array. I then run the array through a for loop and outputs the data into an EJS file. This works sometimes. However sometimes the console logs the error at the bottom of this post. When I increase the amount of endpoints i'm requesting this error happens everytime. The error appears to be very random and the error stops at random endpoints. I'm assuming i'm maybe sending to many requests? I eventually want to loop through around 5000 endpoints in this code but i'm struggling just loop through 20. Any help is much appreciated.

  body: new URLSearchParams({ grant_type: 'client_credentials' }),
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Authorization': 'Basic ' + Buffer.from(appId + ':' + appSecret).toString('base64')
  }
})
.then(response => response.json())
.then(token2 => secondtoken(token2))

function secondtoken(token2){
let accesstoken = token2.access_token; 
const promises = [];
for(var i = 0; i < 20;i++){
promises.push(fetch('https://us.api.blizzard.com/profile/wow/character/'+ slug[i]+'/'+ lowercasenames[i] +'?namespace=profile-us&locale=en_US', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${accesstoken}`
    }
  })
  .then(response => response.json()))

}
  Promise.all(promises)
  .then(data => { profiledata(data)})

};
  
function profiledata(data){
  const name = []
  for(var i = 0; i < data.length;i++){
  name.push(data[i].name)
};

console.log(name)
  res.render('index', {
    leaderboard: diomerda,
    rank: rank,
    rating: rating,
    slug: slug,
    faction: faction,
    statsplayed: statsplayed,
    statswon: statswon,
    statslost: statslost,
    race: racename,
    name: name,
   })
  }}});```

The error is below:

D:\Coding\Form 1\node_modules\node-fetch\lib\index.js:1461
                        reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
                               ^
FetchError: request to https://us.api.blizzard.com/profile/wow/character/area-52/toonah?namespace=profile-us&locale=en_US failed, reason: read ECONNRESET
    at ClientRequest.<anonymous> (D:\Coding\Form 1\node_modules\node-fetch\lib\index.js:1461:11)
    at ClientRequest.emit (node:events:520:28)
    at TLSSocket.socketErrorListener (node:_http_client:442:9)
    at TLSSocket.emit (node:events:520:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET'
}


over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I have exact same problem here, did you find the solution for this?

about 4 years ago · Akmal Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!