Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
Axios does not send appropriate error response [React]

I'm trying to handle the error responses from Axios with React, but when i try to console log it the error is Network error and the error.response is undefined.

The request is a simple POST with the Authorization header correctly setted, when I try to do the same request on Postman it works correctly and I'am able to see the error response.

The request is made after the user fills a form and click on a button.

async function create() {
  const response = await Axios.post(
    "/api/disposal-requests/", // the base url is setted when the application mounts `Axios.defaults.baseURL = process.env.REACT_APP_API_URL`
    {
      description: "Description",
      url: "Url",
      key: "Key",
      location_geoname_id: "City",
    }
  );

  return response.data;
}

When a user clicks on a button there is another function that calls the create.

async function onClick() {
  try {
    await create();
    // Everything works fine when there are no errors
  } catch(error) {
    // Here error.response is undefined
  }
}

This is what i receive in the console.log, in the Network tab I can see the error status is 400 but even there there is no error response, I'am able to see the error response only on Postman.

enter image description here

Does anyone know what's wrong here ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Please write await before creat(). so that if any any error occurs, catch with get that

async function onClick() {
    try {
      await create();
      // Everything works fine when there are no errors
    } catch (error) {
      // Here the error response is undefined
    }
  }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda