Skip to content

Commit

Permalink
Fix: JSON::ParserError (MAYBE-MARKETING-3J)
Browse files Browse the repository at this point in the history
  • Loading branch information
revise-dev[bot] authored Feb 17, 2025
1 parent 274b702 commit 49b274e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions app/controllers/stocks/statistics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,24 @@ def show

@stock_statistics = Rails.cache.fetch("stock_statistics/v2/#{@stock.symbol}:#{@stock.mic_code}", expires_in: 24.hours) do
headers = {
"Content-Type" => "application/json",
"Authorization" => "Bearer #{ENV['SYNTH_API_KEY']}",
"X-Source" => "maybe_marketing",
"Content-Type" => "application/json",
"Authorization" => "Bearer #{ENV['SYNTH_API_KEY']}",
"X-Source" => "maybe_marketing",
"X-Source-Type" => "api"
}

response = Faraday.get("https://api.synthfinance.com/tickers/#{@stock.symbol}?mic_code=#{@stock.mic_code}", nil, headers)
parsed_data = JSON.parse(response.body)["data"]
parsed_data && parsed_data["market_data"] ? parsed_data["market_data"] : nil

Check failure on line 26 in app/controllers/stocks/statistics_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingWhitespace: Trailing whitespace detected.
if response.success? && !response.body.empty?
begin
parsed_data = JSON.parse(response.body)["data"]
parsed_data && parsed_data["market_data"] ? parsed_data["market_data"] : nil
rescue JSON::ParserError
nil
end
else
nil
end
end
end
end

0 comments on commit 49b274e

Please sign in to comment.