Skip to content

Commit

Permalink
better error handling in import. datacite/datacite#965
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 23, 2020
1 parent 27c569f commit b448aee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/models/concerns/crosscitable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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={})
Expand Down

0 comments on commit b448aee

Please sign in to comment.