Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

444
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Akmal Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda