fix /filter api - prevent error on exception conditions

This commit is contained in:
Nuwan 2023-12-14 11:34:42 +05:30
parent 9b59ef6121
commit 286841c3d0
2 changed files with 22 additions and 14 deletions

View File

@ -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

View File

@ -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