diff --git a/app/controllers/api/v1/gab_trends_controller.rb b/app/controllers/api/v1/gab_trends_controller.rb index 88b84d04..825b09d9 100644 --- a/app/controllers/api/v1/gab_trends_controller.rb +++ b/app/controllers/api/v1/gab_trends_controller.rb @@ -12,36 +12,44 @@ class Api::V1::GabTrendsController < Api::BaseController if body.nil? || body.empty? Request.new(:get, "https://trends.gab.com/trend-feed/json").perform do |res| + Rails.logger.debug "GabTrendsController: #{type} endpoint res code: #{res.code.to_s}" if res.code == 200 body = res.body_with_limit Redis.current.set("gabtrends:feed", body) Redis.current.expire("gabtrends:feed", 1.hour.seconds) + render json: body else - body = nil + render json: nil end end + else + render json: body end - - render json: body elsif type == 'partner' body = Redis.current.get("gabtrends:partner") if body.nil? || body.empty? Request.new(:get, "https://trends.gab.com/partner").perform do |res| + Rails.logger.debug "GabTrendsController: #{type} endpoint res code: #{res.code.to_s}" if res.code == 200 body = res.body_with_limit Redis.current.set("gabtrends:partner", body) Redis.current.expire("gabtrends:partner", 1.minute.seconds) + render json: body else - body = nil + render json: nil end end + else + render json: body end - - render json: body else raise GabSocial::NotPermittedError end + + rescue HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError, HTTP::Error + Rails.logger.debug "Error fetching gabtrends feed: #{type}" + render json: nil end end diff --git a/app/controllers/api/v1/shop_controller.rb b/app/controllers/api/v1/shop_controller.rb index 81d6b644..452ad44a 100644 --- a/app/controllers/api/v1/shop_controller.rb +++ b/app/controllers/api/v1/shop_controller.rb @@ -14,20 +14,25 @@ class Api::V1::ShopController < Api::BaseController if body.nil? || body.empty? Request.new(:get, "https://shop.dissenter.com/product/group/json").perform do |res| + Rails.logger.debug "ShopController dissenter products endpoint res code: #{res.code.to_s}" if res.code == 200 body = res.body_with_limit Redis.current.set("gabstore:featuredproducts", body) Redis.current.expire("gabstore:featuredproducts", 15.minutes.seconds) + render json: body else - body = nil + render json: nil end end + else + render json: body end - - render json: body else raise GabSocial::NotPermittedError end + rescue HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError, HTTP::Error + Rails.logger.debug "Error fetching dissenter shop: #{type}" + render json: nil end end