Skip to content

Commit

Permalink
Handle rich media error without crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Cl0v1s authored and Clovis committed Apr 1, 2024
1 parent b381247 commit 3286c6f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/pleroma/web/rich_media/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ defmodule Pleroma.Web.RichMedia.Parser do
end

def parse_url(url) do
with {:ok, %Tesla.Env{body: html}} <- Pleroma.Web.RichMedia.Helpers.rich_media_get(url),
{:ok, html} <- Floki.parse_document(html) do
html
|> maybe_parse()
|> Map.put("url", url)
|> clean_parsed_data()
|> check_parsed_data()
try do
with {:ok, %Tesla.Env{body: html}} <- Pleroma.Web.RichMedia.Helpers.rich_media_get(url),
{:ok, html} <- Floki.parse_document(html) do
html
|> maybe_parse()
|> Map.put("url", url)
|> clean_parsed_data()
|> check_parsed_data()
end
rescue
e -> Logger.warning("Fail while fetching rich media for #{url}: #{Exception.format(:error, e, __STACKTRACE__)}")
end
end

Expand Down

0 comments on commit 3286c6f

Please sign in to comment.