mirror of
https://git.youjo.love/youjo/youjo-be.git
synced 2024-11-20 13:59:55 +01:00
rich media: gracefully handle fetching nil URIs
This commit is contained in:
parent
155a884300
commit
8f2f471e94
1 changed files with 10 additions and 2 deletions
|
@ -5,11 +5,19 @@ defmodule Pleroma.Web.RichMedia.Parser do
|
|||
Pleroma.Web.RichMedia.Parsers.OEmbed
|
||||
]
|
||||
|
||||
def parse(nil), do: {:error, "No URL provided"}
|
||||
|
||||
if Mix.env() == :test do
|
||||
def parse(url), do: parse_url(url)
|
||||
else
|
||||
def parse(url),
|
||||
do: Cachex.fetch!(:rich_media_cache, url, fn _ -> parse_url(url) end)
|
||||
def parse(url) do
|
||||
with {:ok, data} <- Cachex.fetch(:rich_media_cache, url, fn _ -> parse_url(url) end) do
|
||||
data
|
||||
else
|
||||
_e ->
|
||||
{:error, "Parsing error"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp parse_url(url) do
|
||||
|
|
Loading…
Reference in a new issue