Skip to content

Commit

Permalink
fail gracefully when attempting to publish, without data, a pid that …
Browse files Browse the repository at this point in the history
…doesn't exist in Hyacinth

- HYACINTH-1050
  • Loading branch information
barmintor committed Jul 19, 2024
1 parent 6e424a1 commit 36774c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/jobs/process_digital_object_import_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def self.find_or_create_digital_object(digital_object_data, user, digital_object
# We're updating data for an existing object
existing_object_for_update(digital_object_data, user)
else
new_object(digital_object_data['digital_object_type']['string_key'], user, digital_object_import)
digital_object_type = digital_object_data['digital_object_type']['string_key'] if digital_object_data['digital_object_type']
new_object(digital_object_type, user, digital_object_import)
end
end

Expand Down Expand Up @@ -109,7 +110,7 @@ def self.existing_object_for_update(digital_object_data, user)
end

def self.new_object(digital_object_type, user, digital_object_import)
digital_object = DigitalObjectType.get_model_for_string_key(digital_object_type).new
digital_object = DigitalObjectType.get_model_for_string_key(digital_object_type || :missing).new
digital_object.created_by = user
digital_object.updated_by = user
digital_object
Expand Down
12 changes: 12 additions & 0 deletions spec/jobs/process_digital_object_import_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@
expect(klass).to receive(:new_object)
klass.find_or_create_digital_object(digital_object_data, user, digital_object_import)
end
context "no digital_object_type given for a new object" do
let(:digital_object) { klass.find_or_create_digital_object(digital_object_data, user, digital_object_import) }
let(:expected_message) { "Invalid DigitalObjectType string key: missing" }
before do
digital_object_data.delete('digital_object_type')
end

it "fails with a legible error" do
expect(digital_object).to be_nil
expect(digital_object_import.digital_object_errors).to include(expected_message)
end
end
end

describe ".handle_unexpected_processing_error" do
Expand Down

0 comments on commit 36774c0

Please sign in to comment.