Skip to content

Commit

Permalink
Merge pull request #13 from alphagov/logging
Browse files Browse the repository at this point in the history
Add basic error logging to MQ consumer
  • Loading branch information
csutter authored Sep 20, 2023
2 parents eea5410 + 040832a commit 77a68d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/commands/consume_published_document_from_message_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@ def call
),
)
message.ack
rescue StandardError => e
Rails.logger.error(
sprintf(
"Failed to handle message\nError: %s\nMessage: %s",
e.message,
message.inspect,
),
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,18 @@
expect(Rails.logger).to have_received(:info)
.with("Received republish: f75d26a3-25a4-4c31-beea-a77cada4ce12 ('Ebola medal for over 3000 heroes')")
end

context "when the message is invalid" do
let(:payload) { { "I am" => "not valid" } }

before do
allow(Rails.logger).to receive(:error)
end

it "logs the error" do
command.call
expect(Rails.logger).to have_received(:error)
end
end
end
end

0 comments on commit 77a68d3

Please sign in to comment.