From 72ccf8335e8b60c4447cffccc2843b10ba23a4c1 Mon Sep 17 00:00:00 2001 From: Jennifer Vendetti Date: Thu, 11 May 2023 14:53:36 -0700 Subject: [PATCH] Refactor parse_json method Fixes "TypeError (no implicit conversion of URI::HTTPS into String)" exceptions with Ruby 3.x. --- app/controllers/application_controller.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 04f03e28f..488cbda5a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,4 @@ require 'uri' -require 'open-uri' require 'net/http' require 'net/https' require 'net/ftp' @@ -29,6 +28,8 @@ class ApplicationController < ActionController::Base EXPIRY_RECENT_MAPPINGS = 60 * 60 # 1:00 hours EXPIRY_ONTOLOGY_SIMPLIFIED = 60 * 1 # 0:01 minute + RETRY_LIMIT = 1 + $trial_license_initialized = false if !$EMAIL_EXCEPTIONS.nil? && $EMAIL_EXCEPTIONS == true @@ -579,22 +580,18 @@ def get_apikey() end def parse_json(uri) - uri = URI.parse(uri) begin - response = open(uri, "Authorization" => "apikey token=#{get_apikey}").read - rescue Exception => error + response = Net::HTTP.get(URI(uri), { 'Authorization' => "apikey token=#{get_apikey}" }) + rescue StandardError => e @retries ||= 0 - if @retries < 1 # retry once only - @retries += 1 - retry - else - raise error - end + raise e unless @retries < RETRY_LIMIT + + @retries += 1 + retry end JSON.parse(response) end - def get_batch_results(params) begin response = RestClient.post REST_URI_BATCH, params.to_json, :content_type => :json, :accept => :json, :authorization => "apikey token=#{get_apikey}"