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

278
Visualizações
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 Respostas
Responde à pergunta

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 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