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
1 changed files with 6 additions and 1 deletions

View File

@ -24,7 +24,9 @@ defmodule Mobilizon.Service.Pictures.Unsplash do
GenericJSONClient.client(headers: [{:Authorization, "Client-ID #{unsplash_access_key()}"}])
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{
url: selected_picture["urls"]["small"],
author: %{
@ -37,6 +39,9 @@ defmodule Mobilizon.Service.Pictures.Unsplash do
}
}
else
{:empty, false} ->
nil
_ ->
nil
end