Skip to content

Commit

Permalink
Add error logging for SendNotificationEmailJob (#21028)
Browse files Browse the repository at this point in the history
* Add error logging for SendNotificationEmailJob

* don't raise

* tests

* test

---------

Co-authored-by: Ryan Johnson <[email protected]>
  • Loading branch information
Thrillberg and rjohnson2011 authored Mar 5, 2025
1 parent 3140358 commit 6543c98
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def perform(notification_type:, form_submission_attempt:, form_number:, user_acc
notification_email
end
rescue => e
StatsD.increment('silent_failure', tags: statsd_tags) if notification_type == :error
raise e
handle_exception(e)
end

private
Expand Down Expand Up @@ -60,6 +59,16 @@ def time_to_send
def statsd_tags
{ 'service' => 'veteran-facing-forms', 'function' => "#{form_number} form submission to Lighthouse" }
end

def handle_exception(e)
Rails.logger.error(
'Error sending simple forms notification email',
message: e.message,
notification_type:,
confirmation_number: config[:confirmation_number]
)
StatsD.increment('silent_failure', tags: statsd_tags) if notification_type == :error
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@
end

context 'SimpleFormsApi::NotificationEmail initialization fails' do
it 'raises an error and increments statsd' do
allow(SimpleFormsApi::NotificationEmail).to receive(:new).and_raise(ArgumentError)
it 'increments statsd' do
allow(SimpleFormsApi::NotificationEmail).to receive(:new)
allow(StatsD).to receive(:increment)

expect do
described_class.new.perform(
notification_type: :error,
form_submission_attempt:,
form_number:,
user_account:
)
end.to raise_error(ArgumentError)
described_class.new.perform(
notification_type: :error,
form_submission_attempt:,
form_number:,
user_account:
)

expect(StatsD).to have_received(:increment).with('silent_failure', tags: anything)
end
end
Expand All @@ -63,18 +62,16 @@
end

context 'SimpleFormsApi::FormUploadNotificationEmail initialization fails' do
it 'raises an error and increments statsd' do
it 'increments statsd' do
allow(SimpleFormsApi::FormUploadNotificationEmail).to receive(:new).and_raise(ArgumentError)
allow(StatsD).to receive(:increment)

expect do
described_class.new.perform(
notification_type: :error,
form_submission_attempt:,
form_number:,
user_account:
)
end.to raise_error(ArgumentError)
described_class.new.perform(
notification_type: :error,
form_submission_attempt:,
form_number:,
user_account:
)
expect(StatsD).to have_received(:increment).with('silent_failure', tags: anything)
end
end
Expand Down

0 comments on commit 6543c98

Please sign in to comment.