mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
Handle streaming response errors
This commit is contained in:
parent
ec8db9d4ee
commit
0a86d2b3ac
2 changed files with 11 additions and 7 deletions
|
@ -119,7 +119,7 @@ defmodule Pleroma.HTTP.AdapterHelper do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#TODO add Finch support once we have an AdapterHelper for it
|
# TODO add Finch support once we have an AdapterHelper for it
|
||||||
@spec can_stream? :: bool()
|
@spec can_stream? :: bool()
|
||||||
def can_stream? do
|
def can_stream? do
|
||||||
case Application.get_env(:tesla, :adapter) do
|
case Application.get_env(:tesla, :adapter) do
|
||||||
|
|
|
@ -11,10 +11,10 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
||||||
|
|
||||||
@spec rich_media_get(String.t()) :: {:ok, String.t()} | get_errors()
|
@spec rich_media_get(String.t()) :: {:ok, String.t()} | get_errors()
|
||||||
def rich_media_get(url) do
|
def rich_media_get(url) do
|
||||||
case Pleroma.HTTP.AdapterHelper.can_stream?() do
|
case Pleroma.HTTP.AdapterHelper.can_stream?() do
|
||||||
true -> stream(url)
|
true -> stream(url)
|
||||||
false -> head_first(url)
|
false -> head_first(url)
|
||||||
end
|
end
|
||||||
|> handle_result(url)
|
|> handle_result(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
||||||
with {_, {:ok, %Tesla.Env{status: 200, body: stream_body, headers: headers}}} <-
|
with {_, {:ok, %Tesla.Env{status: 200, body: stream_body, headers: headers}}} <-
|
||||||
{:head, Pleroma.HTTP.get(url, req_headers(), http_options())},
|
{:head, Pleroma.HTTP.get(url, req_headers(), http_options())},
|
||||||
{_, :ok} <- {:content_type, check_content_type(headers)},
|
{_, :ok} <- {:content_type, check_content_type(headers)},
|
||||||
{_, :ok} <- {:content_length, check_content_length(headers)} do
|
{_, :ok} <- {:content_length, check_content_length(headers)},
|
||||||
body = Enum.into(stream_body, <<>>)
|
body <- Enum.into(stream_body, <<>>) do
|
||||||
{:ok, body}
|
{:ok, body}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,6 +59,10 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
||||||
{:get, _} ->
|
{:get, _} ->
|
||||||
Logger.debug("Rich media error for #{url}: HTTP GET failed")
|
Logger.debug("Rich media error for #{url}: HTTP GET failed")
|
||||||
{:error, :get}
|
{:error, :get}
|
||||||
|
|
||||||
|
{:error, :recv_chunk_timeout} ->
|
||||||
|
Logger.debug("Rich media error for #{url}: HTTP streaming response failed")
|
||||||
|
{:error, :get}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue