Skip to content

Commit

Permalink
Merge pull request #3179 from alphagov/content-modelling/878-notify-e…
Browse files Browse the repository at this point in the history
…rrors

content-modelling/ fix error handling for content embeds
  • Loading branch information
Harriethw authored Mar 5, 2025
2 parents ced7ccc + 434588a commit f609c59
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions app/presenters/content_embed_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def render_embedded_editions(content)
get_content_for_edition(embedded_edition, embed_code),
)
else
Sentry.capture_exception(CommandError.new(
code: 422,
message: "Could not find a live edition for embedded content ID: #{content_reference.content_id}",
))
GovukError.notify(CommandError.new(
code: 422,
message: "Could not find a live edition for embedded content ID: #{content_reference.content_id}",
))
end
end

Expand Down
8 changes: 4 additions & 4 deletions app/services/embedded_content_finder_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def live_content_ids(content_references, locale)
not_found_content_ids = content_references.map(&:content_id) - found_editions.map(&:content_id)

if not_found_content_ids.any?
Sentry.capture_exception(CommandError.new(
code: 422,
message: "Could not find any live editions for embedded content IDs: #{not_found_content_ids.join(', ')}",
))
GovukError.notify(CommandError.new(
code: 422,
message: "Could not find any live editions for embedded content IDs: #{not_found_content_ids.join(', ')}",
))
end
content_references.map(&:content_id) - not_found_content_ids
end
Expand Down
16 changes: 8 additions & 8 deletions spec/presenters/content_embed_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
let(:details) { { body: "some string with a reference: {{embed:contact:#{fake_content_id}}}" } }

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

it "alerts Sentry and returns the expected content" do
expect(Sentry).to receive(:capture_exception).with(CommandError.new(
code: 422,
message: "Could not find a live edition for embedded content ID: #{fake_content_id}",
))
expect(GovukError).to receive(:notify).with(CommandError.new(
code: 422,
message: "Could not find a live edition for embedded content ID: #{fake_content_id}",
))
expect(described_class.new(edition).render_embedded_content(details)).to eq({
body: "some string with a reference: #{expected_value} {{embed:contact:#{fake_content_id}}}",
})
Expand Down
8 changes: 4 additions & 4 deletions spec/services/embedded_content_finder_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@

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

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

Expand Down

0 comments on commit f609c59

Please sign in to comment.