Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 2835eae

Browse files
authored
Merge pull request #1227 from alphagov/log-dataset-errors
Log errors coming from elasticsearch indexing
2 parents 9c1d61c + 2127ce0 commit 2835eae

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

app/models/dataset.rb

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "elasticsearch/model"
2+
require "logger"
23
require "securerandom"
34

45
class Dataset < ApplicationRecord
@@ -36,6 +37,8 @@ def publish
3637
result = __elasticsearch__.index_document(id: uuid)
3738
raise "Failed to publish" if result["_shards"]["failed"].positive?
3839
end
40+
rescue StandardError => e
41+
Rails.logger.error e
3942
end
4043

4144
def unpublish
@@ -45,6 +48,8 @@ def unpublish
4548
raise "Failed to unpublish" if result["_shards"]["failed"].positive?
4649

4750
draft!
51+
rescue StandardError => e
52+
Rails.logger.error e
4853
end
4954

5055
def as_indexed_json(_options = {})

spec/models/dataset_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
allow(subject.__elasticsearch__).to receive(:index_document)
4949
.and_return("_shards" => { "failed" => 1 })
5050

51-
expect { subject.publish }.to raise_error(/Failed to publish/)
51+
expect { subject.publish }.to_not raise_error(/Failed to publish/)
5252
expect(subject.reload.published?).to be_falsey
5353
end
5454
end
@@ -74,7 +74,7 @@
7474
allow(subject.__elasticsearch__).to receive(:delete_document)
7575
.and_return("_shards" => { "failed" => 1 })
7676

77-
expect { subject.unpublish }.to raise_error(/Failed to unpublish/)
77+
expect { subject.unpublish }.to_not raise_error(/Failed to unpublish/)
7878
expect(subject.published?).to be_truthy
7979
end
8080
end

0 commit comments

Comments
 (0)