Current section

Files

Jump to
excontentstack lib excontentstack shared response.ex
Raw

lib/excontentstack/shared/response.ex

defmodule Excontentstack.Shared.Response do
@moduledoc false
def handle_response({:ok, %Req.Response{status: status, body: body}})
when status >= 200 and status < 300,
do: {:ok, body}
def handle_response({:ok, %Req.Response{} = resp}), do: {:error, format_error(resp)}
def handle_response({:error, reason}), do: {:error, reason}
defp format_error(%Req.Response{status: status, body: %{"error_message" => msg}}),
do: {status, msg}
defp format_error(%Req.Response{status: status}), do: {status, "Unknown error"}
end