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

276
Vistas
javascript fetch call on error how to output error causing data

when using the fetch instruction in javascript, in the following format:

fetch (destination, data_packet)
.then(response => response.json())
.then(data => {})
.catch ((error)=>{console.error ('Error: ',error)});

If an error is thrown such as:

Error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Is there away to see the raw data that was received by the call and resulted in the parsing error, rather than just the error message?

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

0

Just in case anyone is looking for something similar found the answer at Fetch API get raw value from Response

fetch(url)
.then(response => response.text()) 
.then((dataStr) => {
    console.log (dataStr);
    let data = JSON.parse(dataStr);
    data...

get content of response as text and then in next phase convert text to JSON - but can output text returned first to see what might be causing the error.

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