Skip to content

Commit

Permalink
return nil on bad data
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Coté authored and Christopher Coté committed Jul 18, 2017
1 parent 9caf4f5 commit 8244334
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/neurio.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ defmodule Neurio do
end

def process_response_body(body) do
parsed = body |> Poison.decode!
parsed
|> Map.get("channels", [])
|> Enum.find(%{}, fn ch ->
case ch |> Map.get("type") do
"CONSUMPTION" -> true
_ -> false
end
end)
|> parse_data
|> map_state(parsed)
case body |> Poison.decode do
{:ok, parsed} ->
parsed
|> Map.get("channels", [])
|> Enum.find(%{}, fn ch ->
case ch |> Map.get("type") do
"CONSUMPTION" -> true
_ -> false
end
end)
|> parse_data
|> map_state(parsed)
{:error, error} -> nil
end
end

defp parse_data(consumption) do
Expand Down

0 comments on commit 8244334

Please sign in to comment.