Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

275
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!