Handle nothing found by unsplash for location

Closes #1187

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-11-07 18:59:46 +01:00
parent 1f23bb421e
commit 7b2eb82d6f
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -24,7 +24,9 @@ defmodule Mobilizon.Service.Pictures.Unsplash do
GenericJSONClient.client(headers: [{:Authorization, "Client-ID #{unsplash_access_key()}"}]) GenericJSONClient.client(headers: [{:Authorization, "Client-ID #{unsplash_access_key()}"}])
with {:ok, %{status: 200, body: body}} <- GenericJSONClient.get(client, url), with {:ok, %{status: 200, body: body}} <- GenericJSONClient.get(client, url),
selected_picture <- Enum.random(body["results"]) do results <- body["results"],
{:empty, false} <- {:empty, Enum.empty?(results)},
selected_picture <- Enum.random(results) do
%Information{ %Information{
url: selected_picture["urls"]["small"], url: selected_picture["urls"]["small"],
author: %{ author: %{
@ -37,6 +39,9 @@ defmodule Mobilizon.Service.Pictures.Unsplash do
} }
} }
else else
{:empty, false} ->
nil
_ -> _ ->
nil nil
end end