Commit some model changes

demo-logs-iteration2
Alberto Miedes Garcés 4 years ago
parent 84d0b8e5b1
commit e476a03303

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

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

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

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

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

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

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

Loading…
Cancel
Save