Skip to content

Commit

Permalink
rescue ObjectNotFoundError in find_or_create_by_ark (#898)
Browse files Browse the repository at this point in the history
* rescue ObjectNotFoundError in find_or_create_by_ark

* Update collection.rb

* Update work.rb

* Update work.rb

* Show complete Errors

* Fix rubocop errors

* Redo error_message split

Co-authored-by: pghorpade <[email protected]>
  • Loading branch information
sourcefilter and pghorpade authored Dec 8, 2021
1 parent b74b25e commit 4bd5a1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ def reindex_extent
# @return [Collection] The Collection with that ARK
# rubocop:disable Metrics/MethodLength
def self.find_or_create_by_ark(ark)
collection = find_by_ark(ark)
return collection if collection
begin
collection = find_by_ark(ark)
return collection if collection
rescue ActiveFedora::ObjectNotFoundError => e
Rails.logger.error e.message
end

collection = Collection.create(
id: Californica::IdGenerator.id_from_ark(ark),
Expand Down
8 changes: 6 additions & 2 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ def self.find_by_ark(ark)
# @param ark [String] The ARK
# @return [Work] The Work with that ARK
def self.find_or_create_by_ark(ark)
work = find_by_ark(ark)
return work if work
begin
work = find_by_ark(ark)
return work if work
rescue ActiveFedora::ObjectNotFoundError => e
Rails.logger.error e.message
end

work = Work.create(
id: Californica::IdGenerator.id_from_ark(ark),
Expand Down

0 comments on commit 4bd5a1b

Please sign in to comment.