简体   繁体   中英

Batch call to API some responses are returning invalid json response body

I have a for each statement which is taking a stock market symbol and running it through a function which fires off a fetch call to retrieve data regarding the symbol.

When running my app I'm getting this returned back in my console.

`Error with CACFetchError: invalid json response body at https://api.iextrading.com/1.0/stock/market/batch?symbols=CAC&types=quote,chart&range=1d&chartInterval=30 reason: Unexpected token < in JSON at position 0`

It would suggest that the response isn't JSON but you can see by visiting it that it is correct and no '<' arrow exists at position 0.

https://api.iextrading.com/1.0/stock/market/batch?symbols=CAC&types=quote,chart&range=1d&chartInterval=30

I'm at a loss on what could be causing this. I've tried setting a timeout delay in case there is a limit on the API, but no luck.

This kind of message is a strong indication that the response is probably HTML and not JSON. Recheck the api endpoint to which you request. And also make sure that the api sends back JSON. Use postman to view the response from api

Edit: also did you call the json() function on the response that you got?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM