Prevent crash when trying to load a favicon from a non-existent URL
This commit is contained in:
parent
a09901e44e
commit
2a5bfb22db
|
@ -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 = <<
|
||||||
|
|
Loading…
Reference in New Issue