yahoo-stock-prices
yahoo-stock-prices copied to clipboard
Cannot read property 'split' of undefined
Can't use at all as it says: Cannot read property 'split' of undefined and does not give any output.
Hi, so I think this might be an error on Yahoo's side. I added a catch after my function call to getHistoricalPrices so that it would recursively call itself if the the error you are mentioning occurred. I made sure to print out 2 blank lines if the function called itself and then ran it 1000 times. No errors occurred this time but there were gaps of 2 blank lines throughout the output, and it seemed that it was affecting all the quotes. So I think when the request is made to yahoo the body it returns isn't always as planned which is why the type error is thrown
So is there any way to fix this issue, or is it just unfixable due to an issue on yahoo's side? Thanks
Right now I think it is unfixable and is a yahoo error, but maybe darthbatman can comment on this
Make sure you use your code inside a trycatch block and also make sure the ticker symbol is all uppercase
What I ended up doing was wrap the code in a function with a counter, and when the exception occurs, it retries the same with an incremented counter. Perhaps an optional param can be added to the function that accepts num of retries?
I fixed the issue by modifying price in yahoo-stock-prices.js
let price = body.split(`"${ticker}":{"sourceInterval"`)[0]
.split('class="Cl(b)"')[1]
.split('active="">')[1]
.split('</fin-streamer>')[0]
I can pull request if people are still using this