Handle nothing found by unsplash for location
Closes #1187 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
1f23bb421e
commit
7b2eb82d6f
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user