Skip to content

Commit

Permalink
Track notify config errors and do not attempt sending if one exists
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamineskola committed Oct 23, 2024
1 parent a09bd93 commit 8c13346
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/services/letter_sending_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def initialize(neighbour, letter_content, letter_type:, resend_reason: nil)
def deliver!
return if resend_reason.nil? && NeighbourLetter.find_by(neighbour:).present? && consultation_letter?

return if @local_authority.notify_error_status.present?

letter_record = NeighbourLetter.new(neighbour:, text: letter_content, resend_reason:)

ActiveRecord::Base.transaction do
Expand All @@ -39,6 +41,16 @@ def deliver!
rescue Notifications::Client::RequestError => e
letter_record.update!(status: "rejected", failure_reason: e.message)
Appsignal.report_error(e)

case e.message
when /email_reply_to_id \S+ does not exist/, /email_reply_to_id is not a valid UUID/
@local_authority.update!(notify_error_status: "bad_email_reply_to_id")
when /Template not found/
@local_authority.update!(notify_error_status: "bad_letter_template_id")
when /Cannot send letters with a team api key/
@local_authority.update!(notify_error_status: "bad_letter_api_key")
end

return
end

Expand Down

0 comments on commit 8c13346

Please sign in to comment.