Skip to content

Commit

Permalink
Add Bamboo.ApiError.build_api_error
Browse files Browse the repository at this point in the history
What changed?
=============

This commit adds a `Bamboo.ApiError.build_api_error` function that is a
counterpart to the `raise_api_error`. That way, adapters can use the
`build_api_error` function to return `{:error, %Bamboo.ApiError{}}`
tuples instead of raising errors.
  • Loading branch information
germsvel committed Feb 18, 2021
1 parent d61e24a commit 86c8d0a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/bamboo/api_error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,28 @@ defmodule Bamboo.ApiError do

raise(__MODULE__, message: message)
end

def build_api_error(message), do: %__MODULE__{message: message}

def build_api_error(service_name, response, params, extra_message \\ "") do
message = """
There was a problem sending the email through the #{service_name} API.
Here is the response:
#{inspect(response, limit: 150)}
Here are the params we sent:
#{inspect(params, limit: 150)}
"""

message =
case extra_message do
"" -> message
em -> message <> "\n#{em}\n"
end

%__MODULE__{message: message}
end
end

0 comments on commit 86c8d0a

Please sign in to comment.