Skip to content

Commit

Permalink
pattern matching with 200 and 201 status
Browse files Browse the repository at this point in the history
  • Loading branch information
TraceyOnim committed Jun 22, 2020
1 parent 5727367 commit ffd4721
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/at_ex/gateway/base_http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,21 @@ defmodule AtEx.Gateway.Base do
@doc """
Process results from calling the gateway
"""
def process_result(result) do
case result do
{:ok, %{status: 201} = res} ->
Jason.decode(res.body)

{:ok, val} ->
{:error, %{status: val.status, message: val.body}}
def process_result({:ok, %{status: 200} = res}) do
Jason.decode(res.body)
end

{:error, val} ->
{:error, val}
end
def process_result({:ok, %{status: 201} = res}) do
Jason.decode(res.body)
end

def process_result({:ok, result}) do
{:error, %{status: result.status, message: result.body}}
end

def process_result({:error, result}) do
{:error, result}
end
end
end
Expand Down

0 comments on commit ffd4721

Please sign in to comment.