Skip to content

Commit

Permalink
Merge pull request #4482 from santiment/catch-json-decode-error-email…
Browse files Browse the repository at this point in the history
…-send

Catch json decode error email response
  • Loading branch information
tspenov authored Nov 21, 2024
2 parents 4c20ff1 + 73ae71e commit 4a990fa
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/sanbase/alerts/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,19 @@ defimpl Sanbase.Alert, for: Any do
payload_html = Earmark.as_html!(payload, breaks: true, timeout: nil, mapper: &Enum.map/2)
name = Sanbase.Accounts.User.get_name(user)

Sanbase.TemplateMailer.send(user.email, Sanbase.Email.Template.alerts_template(), %{
name: name,
username: name,
payload: payload_html
})
|> case do
{:ok, _} -> :ok
{:error, reason} -> {:error, reason}
try do
case Sanbase.TemplateMailer.send(user.email, Sanbase.Email.Template.alerts_template(), %{
name: name,
username: name,
payload: payload_html
}) do
{:ok, _} -> :ok
{:error, reason} -> {:error, %{reason: :email_send_fail, error: reason}}
end
rescue
e in Jason.DecodeError ->
Logger.error("Failed to decode Mailjet response: #{inspect(e)}")
{:error, "Invalid response from email provider"}
end
end

Expand Down

0 comments on commit 4a990fa

Please sign in to comment.