From 2a5bfb22dbf672d5eaf53a7e95638ce7fb7eb985 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 10 Nov 2019 15:05:48 -0500 Subject: [PATCH] Prevent crash when trying to load a favicon from a non-existent URL --- lib/frenzy/task/fetch_favicon.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/frenzy/task/fetch_favicon.ex b/lib/frenzy/task/fetch_favicon.ex index e23a7a1..4f234d0 100644 --- a/lib/frenzy/task/fetch_favicon.ex +++ b/lib/frenzy/task/fetch_favicon.ex @@ -98,9 +98,7 @@ defmodule Frenzy.Task.FetchFavicon do end end - defp fetch_favicon_data(nil), do: {:error, "No href for link"} - - defp fetch_favicon_data(url) do + defp fetch_favicon_data(url) when is_binary(url) do case HTTP.get(url) do {:ok, %HTTPoison.Response{body: body}} -> {:ok, "data:image/png;base64,#{Base.encode64(body)}"} @@ -110,6 +108,8 @@ defmodule Frenzy.Task.FetchFavicon do end end + defp fetch_favicon_data(_), do: {:error, "No or invalid href for link"} + # from https://github.com/elixir-plug/plug/blob/v1.8.3/lib/plug/request_id.ex#L60 defp generate_task_id() do binary = <<