Skip to content

Commit

Permalink
Merge pull request #156 from fewlinesco/CU-9ux5yt_fix_unhandled_error
Browse files Browse the repository at this point in the history
[CU-9ux5yt] Fix unhandled exception

This pull request solves the issue #148 by catching an exception from `gen_smtp` and re-raising it as a `SMTPError`.
  • Loading branch information
MatheusBueno782 committed Nov 17, 2020
2 parents 644740d + e5b8c9f commit ed56af2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/bamboo/adapters/smtp_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ defmodule Bamboo.SMTPAdapter do
config
|> to_gen_smtp_server_config

email
|> Bamboo.Mailer.normalize_addresses()
|> to_gen_smtp_message
|> config[:transport].send_blocking(gen_smtp_config)
|> handle_response
response =
try do
email
|> Bamboo.Mailer.normalize_addresses()
|> to_gen_smtp_message
|> config[:transport].send_blocking(gen_smtp_config)
catch
e ->
raise SMTPError, {:not_specified, e}
end

handle_response(response)
end

@doc false
Expand All @@ -96,6 +103,10 @@ defmodule Bamboo.SMTPAdapter do
raise SMTPError, {reason, detail}
end

defp handle_response({:error, detail}) do
raise SMTPError, {:not_specified, detail}
end

defp handle_response(response) do
{:ok, response}
end
Expand Down

0 comments on commit ed56af2

Please sign in to comment.