I’ve completed the Stock Price Checker project from the Information Security and Quality Assurance certification to the point where all of the functional tests pass intermittently. I emphasize intermittently because when I’m attempting to retrieve stock data from the API and assign it to the res.locals object to pass through my route handler, the application will sometimes error out with an error along the lines of “Cannot read property of ‘01. symbol’ of undefined”. I should be clear that I know the application works and the logic is sound, because like I said, it will pass the tests the majority of the time.
I cannot figure out a fix to prevent this from happening 100% of the time. I’m currently using Promises combined with async/ await functionality, but that isn’t doing the trick completely. I also tried adding a package in to limit the rate at which requests could be submitted to retrieve data from the API, but that also didn’t fix the issue.
I am using an API from Alphavantage (https://www.alphavantage.co/documentation/) to obtain the stock data, since the Google API indicated in the instructions no longer exists. I would like some help figuring out how to prevent this error from happening 100% of the time. I have a feeling that the root cause may lie with the performance available from Alphavantage (given it is a free service), however, I should be able to some sort of delay into my code to circumvent the issue if that is the case.
My Github Repo for this project is here: https://github.com/bloo0178/ISP4
The Glitch page is here; however, I find it’s easier to troubleshoot if you instead download and run the code from my Github Repo - particularly because Glitch will just crash and the reload process doesn’t always do the trick. https://glitch.com/edit/#!/isp4