diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 061c1a795..6b2f7ee02 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -97,6 +97,11 @@ def rich_media_get(url) do end with :ok <- head_check, do: Pleroma.HTTP.get(url, headers, @options) + + rescue + e -> + Logger.error("Failed to fetch rich media: #{inspect(e)}") + {:error, :fetch_error} end defp check_content_type(headers) do diff --git a/test/pleroma/web/rich_media/helpers_test.exs b/test/pleroma/web/rich_media/helpers_test.exs index c6c3ffd6c..3fa7eecef 100644 --- a/test/pleroma/web/rich_media/helpers_test.exs +++ b/test/pleroma/web/rich_media/helpers_test.exs @@ -81,4 +81,9 @@ test "refuses to crawl URLs of private network from posts" do assert %{} = Helpers.fetch_data_for_activity(activity4) assert %{} = Helpers.fetch_data_for_activity(activity5) end + + test "catches errors in fetching" do + Tesla.Mock.mock(fn _ -> raise ArgumentError end) + assert {:error, :fetch_error} == Helpers.rich_media_get("wp-json/oembed/1.0/embed?url=http:%252F%252F") + end end