yahoo-stock-prices icon indicating copy to clipboard operation
yahoo-stock-prices copied to clipboard

Cannot read property 'split' of undefined

Open BEANNSS opened this issue 4 years ago • 6 comments

Can't use at all as it says: Cannot read property 'split' of undefined and does not give any output.

BEANNSS avatar Feb 27 '21 23:02 BEANNSS

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

PrashanthPillay avatar Mar 01 '21 16:03 PrashanthPillay

So is there any way to fix this issue, or is it just unfixable due to an issue on yahoo's side? Thanks

BEANNSS avatar Mar 02 '21 21:03 BEANNSS

Right now I think it is unfixable and is a yahoo error, but maybe darthbatman can comment on this

PrashanthPillay avatar Mar 07 '21 17:03 PrashanthPillay

Make sure you use your code inside a trycatch block and also make sure the ticker symbol is all uppercase

MehbubRashid avatar Mar 16 '21 20:03 MehbubRashid

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?

saranshdhingra avatar Jun 01 '21 17:06 saranshdhingra

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

Alec-Alameddine avatar May 06 '23 03:05 Alec-Alameddine