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

242
Visualizações
axios response destructuring undefined
export async function downloadAndSyncData(
  user_id: number
): Promise<boolean> {
  try {
    const { status, data } = await getProtocols(user_id);
    let { sets } = data;
    if (status === 200) {
      if (sets !== undefined) {
        console.log("entrou aqui");
        sets.map(async set => {
          const callDetail = detailData(set);
          let obj = await insertDataStorage("DetailSchema", callDetail);
        });
      } else {
        console.log("undefined sets");
      }
      return true;
    } else {
      return false;
    }
  } catch (error) {
    throw error;
  } finally {
    await syncOptions();
  }
}

I have a function on my app that make a request from sets to show on a list. sets is an Array of Objects, that comes from my backend on laravel. laravel return

The thing is, sometimes that work, sometimes not. And i didn't understand why. It works with small objects.

test console

On postman, its ok too. postman

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Move destructuring inside if (status === 200) { check. If the status is not 200 then the data might be undefined and you cannot destructure undefined value.

Or you can rewrite your check like that: let sets = data?.sets;, that way you will first check that the data is here, then get sets property value.

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