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

158
Views
Json parse error on api call react-native

I have this Ajax request function.

export async function fetchAllCoinsPromise() {
  const apiCall = await fetch('https://api.coincap.io/v2/assets');
  const jsonResult = await apiCall.json();

  return jsonResult;
}

I call it like this:

  const fetchCoins = () => {
fetchAllCoinsPromise()
  .then(res => console.log(111))
  .catch(err => {
    console.log('err', err);
    fetchCoins();
  });
 };

the reason why I'am doing this recursion is because sometimes I'm getting this strange error: SyntaxError: JSON Parse error: Unexpected identifier "You"] and I thought the async recursion would solve the issue and it does but I am not sure if this is the best solution in case of time complexity. Any suggestions please?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use a filter if you want. It might be a hacky solution but it works.

An example might look like:


if(jsonResult.startsWith('Y')){
  console.log("Error: " + jsonResult);
  tryYourCallAgain();
  } else {
  return jsonResult;
  }

You could use any filter that would catch the error like typeof, includes, etc. Whatever is best in your case.

Pardon if this code is sloppy as I'm relatively new to Javascript, but this worked for me in a similar case. Hope it helps!

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!