Skip to content

Commit 6a43db3

Browse files
authored
Merge pull request #6466 from NHSDigital/log-missing-emails-in-email-delivery-job
Log a warning when `EmailDeliveryJob` can't find email
2 parents d2f3795 + be4f4d3 commit 6a43db3

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

app/jobs/email_delivery_job.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ def perform(
4444
personalisation.parent&.email
4545
end
4646

47-
return if email_address.nil?
47+
if email_address.nil?
48+
Rails.logger.warn(
49+
"Failed to find email address for template #{template_name_sym}, " \
50+
"parent #{personalisation.parent&.id}"
51+
)
52+
return
53+
end
4854

4955
template = NotifyTemplate.find(template_name_sym, channel: :email)
5056
raise UnknownTemplate if template.nil?

spec/jobs/email_delivery_job_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@
165165
expect(notifications_client).not_to receive(:send_email)
166166
perform_now
167167
end
168+
169+
it "writes a warning to the logs" do
170+
expect(Rails.logger).to receive(:warn).with(
171+
/Failed to find email address for template #{template_name}/
172+
)
173+
perform_now
174+
end
168175
end
169176

170177
context "with a consent form" do

0 commit comments

Comments
 (0)