aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2019-03-07 23:18:59 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2019-03-08 22:56:16 +0000
commit2a83c0ba935355b4ada582315de68b456e727af7 (patch)
tree096cfd2609144c5f1e95b04d6eb2db2ef7b87d99
parent46200d8facfa63343360c9e14cf94f34c55c7d53 (diff)
downloadpleroma-2a83c0ba935355b4ada582315de68b456e727af7.tar.gz
http: safely catch erlang exits and elixir errors from hackney (ref #672)
-rw-r--r--lib/pleroma/http/http.ex45
1 files changed, 23 insertions, 22 deletions
diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex
index 26214ef3f..c6d86b3d3 100644
--- a/lib/pleroma/http/http.ex
+++ b/lib/pleroma/http/http.ex
@@ -27,22 +27,29 @@ defmodule Pleroma.HTTP do
"""
def request(method, url, body \\ "", headers \\ [], options \\ []) do
- options =
- process_request_options(options)
- |> process_sni_options(url)
- |> process_adapter_options()
-
- params = Keyword.get(options, :params, [])
-
- %{}
- |> Builder.method(method)
- |> Builder.headers(headers)
- |> Builder.opts(options)
- |> Builder.url(url)
- |> Builder.add_param(:body, :body, body)
- |> Builder.add_param(:query, :query, params)
- |> Enum.into([])
- |> (&Tesla.request(Connection.new(), &1)).()
+ try do
+ options =
+ process_request_options(options)
+ |> process_sni_options(url)
+
+ params = Keyword.get(options, :params, [])
+
+ %{}
+ |> Builder.method(method)
+ |> Builder.headers(headers)
+ |> Builder.opts(options)
+ |> Builder.url(url)
+ |> Builder.add_param(:body, :body, body)
+ |> Builder.add_param(:query, :query, params)
+ |> Enum.into([])
+ |> (&Tesla.request(Connection.new(), &1)).()
+ rescue
+ e ->
+ {:error, e}
+ catch
+ :exit, e ->
+ {:error, e}
+ end
end
defp process_sni_options(options, nil), do: options
@@ -57,12 +64,6 @@ defmodule Pleroma.HTTP do
end
end
- def process_adapter_options(options) do
- adapter_options = Pleroma.Config.get([:http, :adapter], [])
-
- options ++ [adapter: adapter_options]
- end
-
def process_request_options(options) do
config = Application.get_env(:pleroma, :http, [])
proxy = Keyword.get(config, :proxy_url, nil)