diff --git a/app/models/url.rb b/app/models/url.rb index 460b8a4d..c6b1bb68 100644 --- a/app/models/url.rb +++ b/app/models/url.rb @@ -80,12 +80,16 @@ class Url < ApplicationRecord end def add_click!(client_ip) - uri = URI.parse("http://freegeoip.net/json/#{client_ip}") + begin + uri = URI.parse("http://freegeoip.net/json/#{client_ip}") - result = Net::HTTP.start(uri.host, uri.port) do |http| - request = Net::HTTP::Get.new uri - response = http.request request - response.body + result = Net::HTTP.start(uri.host, uri.port) do |http| + request = Net::HTTP::Get.new uri + response = http.request request + response.body + end + rescue + result = '' end country_code = if result.include?('country_code')