mailgun_ex v0.2.8 MailgunEx.Response View Source

Take a raw HTTPoison response and normalize it down into a 3-tuple response.

For successful responses (i.e. we got an answer back, not necessarily what we wanted, but the API did send us back something), we return the following structure:

{status_code, raw_body, headers}

For example,

{200, "{\"answer\": 42}", [{"Content-Type", "application/json"}]}

If however, an error occurs (as in we couldn’t reach the service at all), we return (still a 3-tuple) with the following structure:

{:error, reason, []}

For example,

{:error, :nxdomain, []}

Note that we do not send back any headers for errors, just a :error atom and a reason (which could be an atom, a string, or maybe even a JSON like response).

Link to this section Summary

Functions

Normalize the HTTPoison response into it’s usable form within this library

Link to this section Functions

Normalize the HTTPoison response into it’s usable form within this library.

Example

iex> MailgunEx.Response.normalize({:ok, %{body: "{\"answer\": 42}", status_code: 200, headers: [{"Content-Type", "application/json"}]}})
{200, "{\"answer\": 42}", [{"Content-Type", "application/json"}]}

iex> MailgunEx.Response.normalize({:error, %{reason: :nxdomain}})
{:error, :nxdomain, []}