I'm trying handle the response from an API call using HTTPoison
In my app context I have
def add_to_cart(data, user) do
case HTTPoison.post!(
"https://api.moltin.com/v2/carts/" <> user <>
"/items", data,
[{"Authorization",
"Bearer #{Agent.get(:token, fn state -> state end)}"},
{"Content-Type", "application/json"}] do
{:ok, %HTTPoison.Response{status_code: 201, body: body}} ->
case Poison.decode(body) do
{:ok, decoded} -> decoded
{:error, error} -> {:error, error}
end
{:ok, %HTTPoison.Response{status_code: 404}} ->
IO.puts "Not found :("
{:error, %HTTPoison.Error{reason: reason}} ->
IO.inspect reason
end
end
The error I return is:
CaseClauseError at POST /order
no case clause matching: %HTTPoison.Response{response content}
I have used this pattern elsewhere in my code and it matches fine but when I place it here, it doesn't seem to work.
I'm sure this isn't enough information with which to work but I'm not sure at this point what else to put. Any guidance would be appreciated.
case HTTPoison.post!(should have beencase HTTPoison.post(, i.e. without the!afterpost. - Kenny Evitt