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

99
Visualizações
Javascript Promise Resolution Dilemma

So basically, I'm new to Javascript and was just wondering as to why I couldn't

  1. Fetch some info from a database
  2. Combine that info with some local info, to make one big JSON set
  3. Send that off to another function when called

// This function fetches some data from a db and combines it with local data
async function axer (){

    // Gets database info 
    const resp = await axios.get('http://localhost:3004/api/prod');

    // Local modification to it
    resp.data.spec = analyticsDashboardAppDB.widgets;

    Returns the big final json file to the function below this
    return await resp.data;
}

// This function sends it off when called by another function in a different js file
mock.onGet('/api/analytics-dashboard-app/widgets').reply( async config => {

    await axer().then(async r => {return [200, await r]})
    
});

When I run this, I keep getting an error saying

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'config')
   at handle_request.js:87:1

If I remove the async from config and the relevant awaits, I get the following error

Cannot read properties of undefined (reading 'then')

When I print the json file before sending it, it logs it exactly as I need it, but after I send it, only the database info is present and no local modification is. The length is the same before and after I send it though, which makes me believe the local modification to the json comes up as undefined once it's called by another function.

I'm pretty sure this has to do with my incomplete understanding of promises so if someone could help me out with this, I'd highly appreciate it.

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