Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HTTPoison error messaging in MISP.HTTP.handle_response/1 #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ defmodule MISP.HTTP do
]
end

defp defaults(), do: [timeout: 100 * 60]
defp client_options(options), do: Keyword.get(options, :client_config, [])

defp client_config(options),
do: Keyword.merge(defaults(), client_options(options))

@doc """
An HTTP GET Request

Expand All @@ -26,7 +32,7 @@ defmodule MISP.HTTP do
|> URI.to_string()
|> HTTPoison.get(
headers(options),
timeout: 100 * 60
client_config(options)
)
|> handle_response()
|> decode_response(decode_as)
Expand All @@ -48,7 +54,7 @@ defmodule MISP.HTTP do
|> HTTPoison.post(
Poison.encode!(body),
headers(options),
timeout: 100 * 60
client_config(options)
)
|> handle_response()
|> decode_response(decode_as)
Expand All @@ -69,7 +75,7 @@ defmodule MISP.HTTP do
|> URI.to_string()
|> HTTPoison.delete(
headers(options),
timeout: 100 * 60
client_config(options)
)
|> handle_response()
|> decode_response(nil)
Expand All @@ -83,8 +89,8 @@ defmodule MISP.HTTP do
{:ok, %HTTPoison.Response{status_code: _, body: body}} ->
{:error, body}

{:error, %HTTPoison.Error{reason: reason}} ->
{:error, "HTTP Error #{reason}"}
{:error, %HTTPoison.Error{} = e} ->
{:error, "HTTP Error #{HTTPoison.Error.message(e)}"}
end
end

Expand Down
10 changes: 5 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ defmodule MISP.MixProject do
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger, :httpoison]
extra_applications: [:logger, :eex, :httpoison]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:httpoison, "~> 1.4"},
{:poison, "~> 3.1"},
{:httpoison, "~> 1.8"},
{:poison, "~> 4.0.1"},
{:ex_doc, ">= 0.0.0", only: :dev},
{:typed_struct, "~> 0.1.4"},
{:typed_struct, "~> 0.2.1"},
{:accessible, "~> 0.2.1"},
{:jason, "~> 1.1.2"}
{:jason, "~> 1.2"}
]
end
end