Prevent crash when trying to load a favicon from a non-existent URL

This commit is contained in:
Shadowfacts 2019-11-10 15:05:48 -05:00
parent a09901e44e
commit 2a5bfb22db
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 3 additions and 3 deletions

View File

@ -98,9 +98,7 @@ defmodule Frenzy.Task.FetchFavicon do
end end
end end
defp fetch_favicon_data(nil), do: {:error, "No href for link"} defp fetch_favicon_data(url) when is_binary(url) do
defp fetch_favicon_data(url) do
case HTTP.get(url) do case HTTP.get(url) do
{:ok, %HTTPoison.Response{body: body}} -> {:ok, %HTTPoison.Response{body: body}} ->
{:ok, "data:image/png;base64,#{Base.encode64(body)}"} {:ok, "data:image/png;base64,#{Base.encode64(body)}"}
@ -110,6 +108,8 @@ defmodule Frenzy.Task.FetchFavicon do
end end
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 # from https://github.com/elixir-plug/plug/blob/v1.8.3/lib/plug/request_id.ex#L60
defp generate_task_id() do defp generate_task_id() do
binary = << binary = <<