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

228
Vistas
React: onClick I want to download the csv files, with queryparam and if download fails due to wrong params want to display popup message

onClick I want to download the csv files, with queryparam and if download fails due to wrong params want to display popup message

Here is my onClick doSubmit method,

 const doSubmit = () => {
    let timeZoneoffset = new Date().getTimezoneOffset();
    let location = `${apiEndpoint}/export-device-data?fromDate=${fromDateTime}&toDate=${toDateTime}&userId=${values.userId}&deviceTypeId=${deviceId}&timeZoneoffset=${timeZoneoffset}`;
    window.open(location, '_blank');
  };

with the above code I am able to download the csv file if I pass the correct params values. But when I pass the incorrect params values getting error object in new tab:

{"status":false,"responseCode":400,"message":"Invalid Request"}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I would suggest you to make a "GET" AJAX call and only if you get 200 as the HTTP status code then you should open the popup and load the page. And if you get > 400 in HTTP status code then show a popup.

fetch("linkedin.com")
.then(data => {
if(data.status < 400)
//popup
else
//display error message
enter code here
})

But with this you ll end up sending 2 requests to load the page.

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