Skip to content

Commit

Permalink
Implementing IIIFResource::IndexingError to handle IIIFResource reind…
Browse files Browse the repository at this point in the history
…exing errors
  • Loading branch information
jrgriffiniii committed Feb 21, 2019
1 parent 1aebe94 commit 2f707f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 5 additions & 3 deletions app/models/iiif_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class IIIFResource < Spotlight::Resources::IiifHarvester
before_save :set_noid

class InvalidIIIFManifestError < TypeError; end
class IndexingError < StandardError; end

def iiif_manifests
@iiif_manifests ||= validate_iiif_manifest_collections!
Expand Down Expand Up @@ -61,9 +62,10 @@ def write_to_index(batch)

blacklight_solr.update data: documents.to_json,
headers: { 'Content-Type' => 'application/json' }
rescue RSolr::Error::Http => rsolr_error
Rails.logger.error "Failed to update Solr for the following documents: #{document_ids.join(', ')}"
raise rsolr_error
rescue RSolr::Error::Http
error_message = "Failed to update Solr for the following documents: #{document_ids.join(', ')}"
Rails.logger.error error_message
raise IndexingError, error_message
end

# Override hard commit after indexing every document, for performance.
Expand Down
5 changes: 2 additions & 3 deletions spec/models/iiif_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,14 @@
docs = resource.document_builder.documents_to_index
docs.map { |document| document[:id] }
end
let(:error_message) { "Failed to update Solr for the following documents: #{ids.join(', ')}" }

before do
allow(Rails.logger).to receive(:error)
allow(blacklight_solr).to receive(:update).and_raise(rsolr_error)
end

it 'logs an error' do
expect { resource.reindex }.to raise_error(rsolr_error)
expect(Rails.logger).to have_received(:error).with("Failed to update Solr for the following documents: #{ids.join(', ')}")
expect { resource.reindex }.to raise_error(IIIFResource::IndexingError, error_message)
end
end
end
Expand Down

0 comments on commit 2f707f1

Please sign in to comment.