tyrauber / stock_quote

A ruby gem that retrieves stock quotes from IEX
MIT License
210 stars 57 forks source link

App crashes if IEX returns 404 #69

Closed cshields1 closed 1 year ago

cshields1 commented 2 years ago

Currently trying to prevent junky user input on a search form. If I search for a symbol that doesn't exist, IEX returns a 404 and my app crashes showing a 404 response ("Unknown symbol").

Using Ruby 3.1.2 and Rails 7.0.2. Please let me know what other information I can provide.

Screen Shot 2022-05-01 at 4 15 35 PM

tyrauber commented 2 years ago

Hi @cshields1, the library throws an error if IEX returns anything but a 200, [here].(https://github.com/tyrauber/stock_quote/blob/master/lib/stock_quote/stock.rb#L67)

 raise response.body unless response.code == 200

One way to handle this, is wrap the query in a rescue and handle the error.


  @stock = StockQuote::Stock.quote(param[:symbol])
rescue => e
   # Handle error here