diff --git a/app/models/asset.rb b/app/models/asset.rb index 29f3597072..41434a0897 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -133,8 +133,8 @@ class Asset < Sequel::Model local_url = CGI.unescape(public_url.gsub(/(http:)?\/\/#{CartoDB.account_host}/, '')) begin FileUtils.rm((public_uploaded_assets_path + local_url).gsub('/uploads/uploads/', '/uploads/')) - rescue => e - CartoDB::Logger.error(message: "Error removing asset", asset: self, exception: e) + rescue StandardError => e + log_error(message: "Error removing asset", current_user: self, exception: e) end return end diff --git a/app/models/carto/api_key.rb b/app/models/carto/api_key.rb index cc7e548bdd..7253ad82e5 100644 --- a/app/models/carto/api_key.rb +++ b/app/models/carto/api_key.rb @@ -593,8 +593,8 @@ module Carto def db_run(query, connection = db_connection) connection.execute(query) rescue ActiveRecord::StatementInvalid => e - CartoDB::Logger.warning(message: 'Error running SQL command', exception: e) - return if e.message =~ /OWNED BY/ # role might not exist becuase it has been already dropped + log_warning(message: 'Error running SQL command', exception: e) + return if e.message =~ /OWNED BY/ # role might not exist becuase it has been already dropped raise_unprocessable_entity_error(e) end diff --git a/app/models/carto/helpers/billing.rb b/app/models/carto/helpers/billing.rb index 6436bfddd8..c73472b2b5 100644 --- a/app/models/carto/helpers/billing.rb +++ b/app/models/carto/helpers/billing.rb @@ -41,14 +41,14 @@ module Carto::Billing def remaining_days_deletion return nil unless state == STATE_LOCKED - begin - deletion_date = Cartodb::Central.new.get_user(username).fetch('scheduled_deletion_date', nil) - return nil unless deletion_date - (deletion_date.to_date - Date.today).to_i - rescue => e - CartoDB::Logger.warning(exception: e, message: 'Something went wrong calculating the number of remaining days for account deletion') - return nil - end + + deletion_date = Cartodb::Central.new.get_user(username).fetch('scheduled_deletion_date', nil) + return nil unless deletion_date + + (deletion_date.to_date - Date.today).to_i + rescue StandardError => e + log_warning(exception: e, message: 'Error calculating remaining days for account deletion') + nil end def enterprise? diff --git a/app/models/carto/helpers/user_commons.rb b/app/models/carto/helpers/user_commons.rb index f6e3e32c4d..1d03e494fd 100644 --- a/app/models/carto/helpers/user_commons.rb +++ b/app/models/carto/helpers/user_commons.rb @@ -86,21 +86,6 @@ module Carto::UserCommons @oauths ||= CartoDB::OAuths.new(self) end - def remaining_days_deletion - return nil unless state == STATE_LOCKED - - begin - deletion_date = Cartodb::Central.new.get_user(username).fetch('scheduled_deletion_date', nil) - return nil unless deletion_date - - (deletion_date.to_date - Date.today).to_i - rescue StandardError => e - message = 'Something went wrong calculating the number of remaining days for account deletion' - CartoDB::Logger.warning(exception: e, message: message) - return nil - end - end - def unverified? (active? || locked?) && email_verification_token.present? && @@ -264,6 +249,7 @@ module Carto::UserCommons viewer ? 'viewer' : 'builder' end + # pending to replace .to_hash with .to_h, and monkeypatch Sequel model to respond to attributes def logging_attrs if self.respond_to?(:attributes) # AR @@ -287,7 +273,7 @@ module Carto::UserCommons license_srv.add_to_redis(attributes[:do_dataset]) else message = 'Error updating a DO subscription: unknown action' - CartoDB::Logger.error(message: message) + log_error(message: message) raise message end end diff --git a/app/models/common_data.rb b/app/models/common_data.rb index feeb1a3d28..33e7549bc1 100644 --- a/app/models/common_data.rb +++ b/app/models/common_data.rb @@ -5,6 +5,8 @@ require_relative '../../lib/carto_api/json_client' class CommonData + include ::LoggerHelper + def initialize(visualizations_api_url) @datasets = nil @http_client = Carto::Http::Client.get('common_data', log_requests: true) @@ -27,16 +29,16 @@ class CommonData @datasets = get_datasets(response.response_body) redis_cache.set(is_https_request, response.headers, response.response_body) else - CartoDB::Logger.warning(message: "Error retrieving common data datasets", response: response.to_s) + log_warning(message: "Error retrieving common data datasets", error_detail: response.inspect) end rescue StandardError => e - CartoDB::Logger.error(exception: e) + log_error(exception: e) end else @datasets = get_datasets(cached_data[:body]) end - CartoDB::Logger.error(message: 'common-data empty', url: @visualizations_api_url) if @datasets.empty? + log_error(message: 'common-data empty', url: @visualizations_api_url) if @datasets.empty? end @datasets @@ -52,7 +54,7 @@ class CommonData begin rows = JSON.parse(json).fetch('visualizations', []) rescue StandardError => e - CartoDB::Logger.error(exception: e) + log_error(exception: e) rows = [] end diff --git a/app/models/data_import.rb b/app/models/data_import.rb index 5f500f0338..99dff36b83 100644 --- a/app/models/data_import.rb +++ b/app/models/data_import.rb @@ -304,7 +304,7 @@ class DataImport < Sequel::Model end rescue Addressable::URI::InvalidURIError # this should only happen in testing, but just in case capture and log - CartoDB::Logger.warning(message: 'InvalidURIError when processing data_source', data_source: data_source) + log_warning(message: 'InvalidURIError when processing data_source', data_source: data_source) end end @@ -1202,9 +1202,8 @@ class DataImport < Sequel::Model origin: origin)).report end end - rescue => exception - CartoDB::Logger.warning(message: 'Carto::Tracking: Couldn\'t report event', - exception: exception) + rescue StandardError => e + log_warning(message: "Carto::Tracking: Couldn't report event", exception: e) end def sync? diff --git a/app/models/geocoding.rb b/app/models/geocoding.rb index 2bbab7b02b..80a79a8f9b 100644 --- a/app/models/geocoding.rb +++ b/app/models/geocoding.rb @@ -224,7 +224,7 @@ class Geocoding < Sequel::Model if translated_formatter =~ SANITIZED_FORMATTER_REGEXP translated_formatter else - CartoDB::Logger.warning(message: %{Incorrect formatter string received: "#{formatter}"}, user: user) + log_warning(message: 'Incorrect formatter string received', current_user: user, error_detail: formatter) '' end end