From 84481a4fec38081f9ab6e496c04fa297771d323a Mon Sep 17 00:00:00 2001 From: Nuwan Date: Thu, 14 Dec 2023 11:34:42 +0530 Subject: [PATCH] fix /filter api - prevent error on exception conditions --- ruby/lib/jam_ruby/lib/musician_filter.rb | 31 +++++++++++++------- web/app/controllers/api_search_controller.rb | 5 ++-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ruby/lib/jam_ruby/lib/musician_filter.rb b/ruby/lib/jam_ruby/lib/musician_filter.rb index db5a8d092..84b1f4193 100644 --- a/ruby/lib/jam_ruby/lib/musician_filter.rb +++ b/ruby/lib/jam_ruby/lib/musician_filter.rb @@ -8,7 +8,7 @@ module JamRuby me: { label: 'ME', min: -1, max: -1 }, unknown: { label: 'UNKNOWN', min: -2, max: -2 } }; - + def self.filter(user, remote_ip, params) #debugger latency_good = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:latency_good]) @@ -17,8 +17,12 @@ module JamRuby offset = [params[:offset].to_i, 0].max limit = [params[:limit].to_i, 20].max filter_params = {} - - filter_params.merge!(from_location: params[:from_location] ? '1' : '0') + + if params[:from_location].present? && params[:from_location].to_s == 'true' + filter_params.merge!(from_location: "1") + else + filter_params.merge!(from_location: "0") + end genres = params[:genres] filter_params.merge!(genres: genres) if genres @@ -68,14 +72,14 @@ module JamRuby [search, latency_data, nextOffset] rescue => exception - logger.debug("Latency exception: #{exception.message}") + #logger.debug("Latency exception: #{exception.message}") Bugsnag.notify(exception) do |report| report.severity = "error" report.add_tab(:latency, { params: params, user_id: user.id, name: user.name, - url: filter_latency_url, + url: latency_url, }) end raise exception @@ -83,9 +87,7 @@ module JamRuby end def self.users_latency_data(user_obj, remote_ip, latency_good, latency_fair, latency_high, filter_opts, offset, limit) - filter_latency_url = "#{APP_CONFIG.latency_data_host}/search_users" - - uri = URI(filter_latency_url) + uri = URI(latency_url) begin http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if APP_CONFIG.latency_data_host.start_with?("https://") @@ -138,22 +140,29 @@ module JamRuby return { data: latency_data, next: nextOffset } else - logger.debug("Latency response failed: #{response}") Bugsnag.notify("LatencyResponseFailed") do |report| report.severity = "faliure" report.add_tab(:latency, { user_id: user_obj.id, name: user_obj.name, - params: params, - url: filter_latency_url, + params: req_params, + url: latency_url, code: response.code, body: response.body, }) end + Rails.logger.debug("Latency response failed: #{response.code} #{response.body}") + raise Exception.new("#{response.code}: #{response.body}") end rescue => exception raise exception end end + + private + + def self.latency_url + "#{APP_CONFIG.latency_data_host}/client#" + end end end \ No newline at end of file diff --git a/web/app/controllers/api_search_controller.rb b/web/app/controllers/api_search_controller.rb index a09e21076..39fc026db 100644 --- a/web/app/controllers/api_search_controller.rb +++ b/web/app/controllers/api_search_controller.rb @@ -181,10 +181,9 @@ class ApiSearchController < ApiController def filter begin @search, @latency_data, @nextOffset = JamRuby::MusicianFilter.filter(current_user, request.remote_ip, params) - Rails.logger.debug("=====SEARCH : #{@search.results.inspect}") - Rails.logger.debug("=====LATENCY : #{@latency_data}") respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/filter' - rescue + rescue => ex + Rails.logger.debug("=====LATENCY EXCEPTION : #{ex.message}") render json: {}, status: 500 end end