Update facts processors error handling
Some checks are pending
ci / docker (push) Waiting to run

This commit is contained in:
Álvaro 2024-06-15 19:06:12 +02:00
parent 1c06ffb8a8
commit 0c0c7f1230
3 changed files with 21 additions and 33 deletions

View File

@ -9,20 +9,16 @@ defmodule LolAnalytics.Facts.ChampionPickedItem.FactProcessor do
"""
@impl true
def process_game_at_url(url) do
case HTTPoison.get(url) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
process_game_data(body)
{:error, %HTTPoison.Error{reason: reason}} ->
{:error, reason}
_ ->
{:error, "Could not fetch data from #{url}"}
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
HTTPoison.get(url),
{:ok, decoded_match} <- Poison.decode(body, as: %LoLAPI.Model.MatchResponse{}) do
process_game_data(decoded_match)
else
_ -> {:error, "Could not process data from #{url}"}
end
end
defp process_game_data(data) do
decoded_match = Poison.decode!(data, as: %LoLAPI.Model.MatchResponse{})
defp process_game_data(decoded_match) do
participants = decoded_match.info.participants
version = extract_game_version(decoded_match)

View File

@ -8,20 +8,16 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.FactProcessor do
@impl true
@spec process_game_at_url(String.t()) :: any()
def process_game_at_url(url) do
case HTTPoison.get(url) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
process_game_data(body)
{:error, %HTTPoison.Error{reason: reason}} ->
{:error, reason}
_ ->
{:error, "Could not fetch data from #{url}"}
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
HTTPoison.get(url),
{:ok, decoded_match} <- Poison.decode(body, as: %LoLAPI.Model.MatchResponse{}) do
process_game_data(decoded_match)
else
_ -> {:error, "Could not process data from #{url}"}
end
end
defp process_game_data(data) do
decoded_match = Poison.decode!(data, as: %LoLAPI.Model.MatchResponse{})
defp process_game_data(decoded_match) do
participants = decoded_match.info.participants
version = extract_game_version(decoded_match)

View File

@ -6,20 +6,16 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.FactProcessor do
@impl true
@spec process_game_at_url(String.t()) :: none()
def process_game_at_url(url) do
case HTTPoison.get(url) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
process_game_data(body)
{:error, %HTTPoison.Error{reason: reason}} ->
{:error, reason}
_ ->
{:error, "Could not fetch data from #{url}"}
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
HTTPoison.get(url),
{:ok, decoded_match} <- Poison.decode(body, as: %LoLAPI.Model.MatchResponse{}) do
process_game_data(decoded_match)
else
_ -> {:error, "Could not process data from #{url}"}
end
end
def process_game_data(data) do
decoded_match = Poison.decode!(data, as: %LoLAPI.Model.MatchResponse{})
def process_game_data(decoded_match) do
participants = decoded_match.info.participants
version = extract_game_version(decoded_match)