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

141
Visualizações
NETWORK ERROR does not get resolved by axios

I'm sending a request to a backend THAT IS OFFLINE using axios

const backendClient = axios.create({
  baseURL : env
});

The API gets called

export const createExpensesRecord = async (createExpenseRecordCmd) => {
    try {
        await backendClient.post("/api/accounting/expenses", createExpenseRecordCmd)
        return true
    } catch(error) {
        return false
    }
}

The error code should trigger, as the backend is not reachable with Error: Network Error.

function submitAccountingRecord() {
        if(formDataValid()) {
            
            if(createExpensesRecord(cmd)) {
                console.log("SUCCESS")
            } else {
                console.log("FAILED")
            }

            ...
        }
    }

No matter what I do, I always receive SUCCESS. Played around with it for over an hour and couldn't get consistant behaviour. What am I doing wrong?

Be aware that I tried multiple approaches, maybe we can stick to this one than suggestion different options to solve it. It's the most straight forward approach I could think of

---- UPDATE

await function submitAccountingRecord() {
        if(formDataValid()) {
            
            if(await createExpensesRecord(cmd)) {
                console.log("SUCCESS")
            } else {
                console.log("FAILED")
            }

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

0

Server being offline is not an error really. In fact, you shouldn't rely on any HTTP tool (be it axios or native fetch API). Read this thread to learn more.

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