RichMedia: do not log webpages missing metadata as errors
Also fixes the return value of Parser.parse on errors, previously was just `:ok` due to the logger call in the end
This commit is contained in:
parent
047a60c46e
commit
170599c390
|
@ -21,8 +21,13 @@ def parse(url) do
|
||||||
{:ok, _} <- set_ttl_based_on_image(data, url) do
|
{:ok, _} <- set_ttl_based_on_image(data, url) do
|
||||||
{:ok, data}
|
{:ok, data}
|
||||||
else
|
else
|
||||||
|
{:error, {:invalid_metadata, data}} = e ->
|
||||||
|
Logger.debug(fn -> "Incomplete or invalid metadata for #{url}: #{inspect(data)}" end)
|
||||||
|
e
|
||||||
|
|
||||||
error ->
|
error ->
|
||||||
Logger.error(fn -> "Rich media error: #{inspect(error)}" end)
|
Logger.error(fn -> "Rich media error for #{url}: #{inspect(error)}" end)
|
||||||
|
error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -90,7 +95,7 @@ defp get_ttl_from_image(data, url) do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp parse_url(url) do
|
def parse_url(url) do
|
||||||
with {:ok, %Tesla.Env{body: html}} <- Pleroma.Web.RichMedia.Helpers.rich_media_get(url),
|
with {:ok, %Tesla.Env{body: html}} <- Pleroma.Web.RichMedia.Helpers.rich_media_get(url),
|
||||||
{:ok, html} <- Floki.parse_document(html) do
|
{:ok, html} <- Floki.parse_document(html) do
|
||||||
html
|
html
|
||||||
|
@ -116,7 +121,7 @@ defp check_parsed_data(%{"title" => title} = data)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp check_parsed_data(data) do
|
defp check_parsed_data(data) do
|
||||||
{:error, "Found metadata was invalid or incomplete: #{inspect(data)}"}
|
{:error, {:invalid_metadata, data}}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp clean_parsed_data(data) do
|
defp clean_parsed_data(data) do
|
||||||
|
|
|
@ -66,9 +66,7 @@ test "returns error when no metadata present" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "doesn't just add a title" do
|
test "doesn't just add a title" do
|
||||||
assert Parser.parse("http://example.com/non-ogp") ==
|
assert {:error, {:invalid_metadata, _}} = Parser.parse("http://example.com/non-ogp")
|
||||||
{:error,
|
|
||||||
"Found metadata was invalid or incomplete: %{\"url\" => \"http://example.com/non-ogp\"}"}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "parses ogp" do
|
test "parses ogp" do
|
||||||
|
|
Loading…
Reference in New Issue