forked from AkkomaGang/akkoma
http: safely catch erlang exits and elixir errors from hackney (ref #672)
This commit is contained in:
parent
46200d8fac
commit
2a83c0ba93
1 changed files with 21 additions and 20 deletions
|
@ -27,10 +27,10 @@ defmodule Pleroma.HTTP do
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def request(method, url, body \\ "", headers \\ [], options \\ []) do
|
def request(method, url, body \\ "", headers \\ [], options \\ []) do
|
||||||
|
try do
|
||||||
options =
|
options =
|
||||||
process_request_options(options)
|
process_request_options(options)
|
||||||
|> process_sni_options(url)
|
|> process_sni_options(url)
|
||||||
|> process_adapter_options()
|
|
||||||
|
|
||||||
params = Keyword.get(options, :params, [])
|
params = Keyword.get(options, :params, [])
|
||||||
|
|
||||||
|
@ -43,6 +43,13 @@ defmodule Pleroma.HTTP do
|
||||||
|> Builder.add_param(:query, :query, params)
|
|> Builder.add_param(:query, :query, params)
|
||||||
|> Enum.into([])
|
|> Enum.into([])
|
||||||
|> (&Tesla.request(Connection.new(), &1)).()
|
|> (&Tesla.request(Connection.new(), &1)).()
|
||||||
|
rescue
|
||||||
|
e ->
|
||||||
|
{:error, e}
|
||||||
|
catch
|
||||||
|
:exit, e ->
|
||||||
|
{:error, e}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp process_sni_options(options, nil), do: options
|
defp process_sni_options(options, nil), do: options
|
||||||
|
@ -57,12 +64,6 @@ defmodule Pleroma.HTTP do
|
||||||
end
|
end
|
||||||
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
|
def process_request_options(options) do
|
||||||
config = Application.get_env(:pleroma, :http, [])
|
config = Application.get_env(:pleroma, :http, [])
|
||||||
proxy = Keyword.get(config, :proxy_url, nil)
|
proxy = Keyword.get(config, :proxy_url, nil)
|
||||||
|
|
Loading…
Reference in a new issue