Skip to content

Commit f609c59

Browse files
authored
Merge pull request #3179 from alphagov/content-modelling/878-notify-errors
content-modelling/ fix error handling for content embeds
2 parents ced7ccc + 434588a commit f609c59

4 files changed

+20
-20
lines changed

app/presenters/content_embed_presenter.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def render_embedded_editions(content)
6565
get_content_for_edition(embedded_edition, embed_code),
6666
)
6767
else
68-
Sentry.capture_exception(CommandError.new(
69-
code: 422,
70-
message: "Could not find a live edition for embedded content ID: #{content_reference.content_id}",
71-
))
68+
GovukError.notify(CommandError.new(
69+
code: 422,
70+
message: "Could not find a live edition for embedded content ID: #{content_reference.content_id}",
71+
))
7272
end
7373
end
7474

app/services/embedded_content_finder_service.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def live_content_ids(content_references, locale)
2727
not_found_content_ids = content_references.map(&:content_id) - found_editions.map(&:content_id)
2828

2929
if not_found_content_ids.any?
30-
Sentry.capture_exception(CommandError.new(
31-
code: 422,
32-
message: "Could not find any live editions for embedded content IDs: #{not_found_content_ids.join(', ')}",
33-
))
30+
GovukError.notify(CommandError.new(
31+
code: 422,
32+
message: "Could not find any live editions for embedded content IDs: #{not_found_content_ids.join(', ')}",
33+
))
3434
end
3535
content_references.map(&:content_id) - not_found_content_ids
3636
end

spec/presenters/content_embed_presenter_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
let(:details) { { body: "some string with a reference: {{embed:contact:#{fake_content_id}}}" } }
3838

3939
it "alerts Sentry and returns the content as is" do
40-
expect(Sentry).to receive(:capture_exception).with(CommandError.new(
41-
code: 422,
42-
message: "Could not find a live edition for embedded content ID: #{fake_content_id}",
43-
))
40+
expect(GovukError).to receive(:notify).with(CommandError.new(
41+
code: 422,
42+
message: "Could not find a live edition for embedded content ID: #{fake_content_id}",
43+
))
4444
expect(described_class.new(edition).render_embedded_content(details)).to eq({
4545
body: "some string with a reference: {{embed:contact:#{fake_content_id}}}",
4646
})
@@ -73,10 +73,10 @@
7373
let(:details) { { body: "some string with a reference: {{embed:contact:#{embedded_content_id}}} {{embed:contact:#{fake_content_id}}}" } }
7474

7575
it "alerts Sentry and returns the expected content" do
76-
expect(Sentry).to receive(:capture_exception).with(CommandError.new(
77-
code: 422,
78-
message: "Could not find a live edition for embedded content ID: #{fake_content_id}",
79-
))
76+
expect(GovukError).to receive(:notify).with(CommandError.new(
77+
code: 422,
78+
message: "Could not find a live edition for embedded content ID: #{fake_content_id}",
79+
))
8080
expect(described_class.new(edition).render_embedded_content(details)).to eq({
8181
body: "some string with a reference: #{expected_value} {{embed:contact:#{fake_content_id}}}",
8282
})

spec/services/embedded_content_finder_service_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@
214214

215215
it "alerts Sentry when there is are embeds without live editions" do
216216
details = { body: "{{embed:contact:00000000-0000-0000-0000-000000000000}}" }
217-
expect(Sentry).to receive(:capture_exception).with(CommandError.new(
218-
code: 422,
219-
message: "Could not find any live editions for embedded content IDs: 00000000-0000-0000-0000-000000000000",
220-
))
217+
expect(GovukError).to receive(:notify).with(CommandError.new(
218+
code: 422,
219+
message: "Could not find any live editions for embedded content IDs: 00000000-0000-0000-0000-000000000000",
220+
))
221221

222222
links = EmbeddedContentFinderService.new.fetch_linked_content_ids(details, "foo")
223223

0 commit comments

Comments
 (0)