From b448aeef8bdd5d6eb56b4e366f685d9569d0c505 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 23 Feb 2020 14:12:29 +0100 Subject: [PATCH] better error handling in import. datacite/datacite#965 --- app/models/concerns/crosscitable.rb | 6 +++--- app/models/doi.rb | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/models/concerns/crosscitable.rb b/app/models/concerns/crosscitable.rb index b7d0474c8..6347096d3 100644 --- a/app/models/concerns/crosscitable.rb +++ b/app/models/concerns/crosscitable.rb @@ -58,9 +58,9 @@ def parse_xml(input, options={}) end def replace_doi(input, options={}) - return input unless options[:doi].present? - - doc = Nokogiri::XML(input, nil, 'UTF-8', &:noblanks) + return input if options[:doi].blank? + + doc = Nokogiri::XML(input, nil, "UTF-8", &:noblanks) node = doc.at_css("identifier") node.content = options[:doi].to_s.upcase if node.present? && options[:doi].present? doc.to_xml.strip diff --git a/app/models/doi.rb b/app/models/doi.rb index 2730877cd..2da859ce1 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -862,10 +862,13 @@ def self.import_one(doi_id: nil) doi.update_attributes(attrs) Rails.logger.info "[MySQL] Imported metadata for DOI " + doi.doi + "." doi - rescue TypeError, NoMethodError, RuntimeError, ActiveRecord::StatementInvalid, ActiveRecord::LockWaitTimeout => error - Rails.logger.error "[MySQL] Error importing metadata for " + doi.doi + ": " + error.message - Raven.capture_exception(error) - doi + rescue TypeError, NoMethodError, RuntimeError, ActiveRecord::StatementInvalid, ActiveRecord::LockWaitTimeout => e + if doi.present? + Rails.logger.error "[MySQL] Error importing metadata for " + doi.doi + ": " + e.message + doi + else + Raven.capture_exception(e) + end end def self.import_by_ids(options={})