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

74
Visualizações
API request in a loop works for two iterations and then crashes out

This query loops through a data object getNewNodes and for each install_key it makes an API call to get a hash of the key by triggering getBcrypt. Sometimes it does the first one or two but then it falls over itself and produces an error "state1.value[i].hash" is not defined. State 1 is a temporary state variable and 'hash' is one of the keys inside the API response. I assumed that the onsuccess: function(data) would return the data from the API response once there was a response but it seems that's not the case. Could one of you kind folks please tell me where I'm going wrong.

const array_key = getNewNodes.data.install_key;
let newData = [];
let i=0
async function delay(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}
async function makeRequests(secure_key){
for (const install_key of array_key){
 
 await getBcrypt.trigger({
  additionalScope: {install_key:install_key},
  onSuccess: function(data){
  state1.setIn([i],data)
  }})
        newData.push({
        install_key: install_key,
        secure_key: state1.value[i].hash
        })  
  console.log(state1.value[i].hash)

i++ }
return newData();
}
return makeRequests();

about 4 years ago · Juan Pablo Isaza
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