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

116
Visualizações
Axios POST response is undefined but network shows a response object

I wanted to include some error information in my app but I am having trouble parsing the response. I am sending a POST request using axios to a remote server to transfer some file like this.

//http is an axios instance
const response = await http.post(url, formData, {
    headers: {
        'content-type': 'multipart/form-data',
      },
    });

if (response) {
    return { errors: false };
} else {
    return {      
        errors: true,
        errorMessages: ['There was an error uploading the file'],
                       //i want to extract errors array from response actually
    };
}

I can upload my file just fine and the backend seems to be validating everything as expected. So when I try to force errors sending invalid files, I see a response is coming back from the backend in the network tab of devtools that looks like this:

{"hasErrors":true,"data":false,"errors":["file extension validation: File must use .xlsx extension."]}

But in my front I can't access neither of those fields in my response variable. The server is responding with code 400.

I appreciate any help as I'm kinda lost trying to log this and don't want to show just a generic error message when server is actually providing this information.

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

0

The trouble here is that axios doesn't resolve post calls with 400-status responses; it throws an error that you can catch.

try {
  const response = await http.post(/* your config */);
  return {errors: false};
} catch (e) {
  const {response} = e;
  return {errors: true};
}
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