aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexander Strizhakov <alex.strizhakov@gmail.com>2020-03-05 17:31:06 +0300
committerAlexander Strizhakov <alex.strizhakov@gmail.com>2020-03-05 17:31:06 +0300
commitf0753eed0fdddd30e127213c89a118dd2e087dc9 (patch)
tree6cf9a2d9983fc42d11bb476aa2ba247b0b9c3338 /lib
parenteb324467d9c5c761a776ffc98347246c61ad02ae (diff)
downloadpleroma-f0753eed0fdddd30e127213c89a118dd2e087dc9.tar.gz
removing try block in tesla request
added mocks for tests which fail with Tesla.Mock.Error
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/http/http.ex24
-rw-r--r--lib/pleroma/pool/request.ex2
-rw-r--r--lib/pleroma/web/push/impl.ex2
-rw-r--r--lib/pleroma/web/web_finger/web_finger.ex3
4 files changed, 9 insertions, 22 deletions
diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex
index 7b7c79b64..466a94adc 100644
--- a/lib/pleroma/http/http.ex
+++ b/lib/pleroma/http/http.ex
@@ -88,15 +88,11 @@ defmodule Pleroma.HTTP do
end
@spec request(Client.t(), keyword(), map()) :: {:ok, Env.t()} | {:error, any()}
- def request(%Client{} = client, request, %{env: :test}), do: request_try(client, request)
+ def request(%Client{} = client, request, %{env: :test}), do: request(client, request)
- def request(%Client{} = client, request, %{body_as: :chunks}) do
- request_try(client, request)
- end
+ def request(%Client{} = client, request, %{body_as: :chunks}), do: request(client, request)
- def request(%Client{} = client, request, %{pool_alive?: false}) do
- request_try(client, request)
- end
+ def request(%Client{} = client, request, %{pool_alive?: false}), do: request(client, request)
def request(%Client{} = client, request, %{pool: pool, timeout: timeout}) do
:poolboy.transaction(
@@ -106,18 +102,8 @@ defmodule Pleroma.HTTP do
)
end
- @spec request_try(Client.t(), keyword()) :: {:ok, Env.t()} | {:error, any()}
- def request_try(client, request) do
- try do
- Tesla.request(client, request)
- rescue
- e ->
- {:error, e}
- catch
- :exit, e ->
- {:error, e}
- end
- end
+ @spec request(Client.t(), keyword()) :: {:ok, Env.t()} | {:error, any()}
+ def request(client, request), do: Tesla.request(client, request)
defp build_request(method, headers, options, url, body, params) do
Builder.new()
diff --git a/lib/pleroma/pool/request.ex b/lib/pleroma/pool/request.ex
index 0f271b3d0..db7c10c01 100644
--- a/lib/pleroma/pool/request.ex
+++ b/lib/pleroma/pool/request.ex
@@ -22,7 +22,7 @@ defmodule Pleroma.Pool.Request do
@impl true
def handle_call({:execute, client, request}, _from, state) do
- response = Pleroma.HTTP.request_try(client, request)
+ response = Pleroma.HTTP.request(client, request)
{:reply, response, state}
end
diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex
index afa510f08..233e55f21 100644
--- a/lib/pleroma/web/push/impl.ex
+++ b/lib/pleroma/web/push/impl.ex
@@ -32,7 +32,7 @@ defmodule Pleroma.Web.Push.Impl do
type = Activity.mastodon_notification_type(notif.activity)
gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key)
avatar_url = User.avatar_url(actor)
- object = Object.normalize(activity)
+ object = Object.normalize(activity) || activity
user = User.get_cached_by_id(user_id)
direct_conversation_id = Activity.direct_conversation_id(activity, user)
diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex
index db567a02e..7ffd0e51b 100644
--- a/lib/pleroma/web/web_finger/web_finger.ex
+++ b/lib/pleroma/web/web_finger/web_finger.ex
@@ -173,7 +173,8 @@ defmodule Pleroma.Web.WebFinger do
get_template_from_xml(body)
else
_ ->
- with {:ok, %{body: body}} <- HTTP.get("https://#{domain}/.well-known/host-meta", []) do
+ with {:ok, %{body: body, status: status}} when status in 200..299 <-
+ HTTP.get("https://#{domain}/.well-known/host-meta", []) do
get_template_from_xml(body)
else
e -> {:error, "Can't find LRDD template: #{inspect(e)}"}