rich media: gracefully handle fetching nil URIs
authorWilliam Pitcock <nenolod@dereferenced.org>
Sat, 26 Jan 2019 16:26:11 +0000 (16:26 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Sat, 26 Jan 2019 16:36:17 +0000 (16:36 +0000)
lib/pleroma/web/rich_media/parser.ex

index 6da83c6e4ab34265be75c1a623980aedd0d022c4..947dc0c3c2fef989d334f431cc4c9f29c2c9275a 100644 (file)
@@ -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