Skip to content

Commit

Permalink
Allow string keys in parsed results
Browse files Browse the repository at this point in the history
I noticed that I was getting atoms in some of my keys, but everywhere else that I use `Jason.decode/1`, I get strings. This causes problems when trying to pattern match some query results. So I updated the config with this:
```
  json_decoder: {Jason, :decode!},
  json_encoder: {Jason, :encode!}
```
And I got errors:
```
[error] GenServer #PID<0.504.0> terminating
** (CaseClauseError) no case clause matching: {:ok, 200, %{"result" => [%{"stuff" => "asdfasdfasdf"}]}}
    (caylir) lib/caylir/graph/request.ex:50: Caylir.Graph.Request.query/3
```
  • Loading branch information
rm-rf-etc authored Nov 17, 2019
1 parent c35bc32 commit f010d2b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/caylir/graph/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule Caylir.Graph.Request do

case response do
{:ok, _, %{error: reason}} -> {:error, reason}
{:ok, _, %{"error" => reason}} -> {:error, reason}
{:ok, 200, _success} -> :ok
end
end
Expand All @@ -49,7 +50,9 @@ defmodule Caylir.Graph.Request do

case response do
{:ok, _, %{error: reason}} -> {:error, reason}
{:ok, _, %{"error" => reason}} -> {:error, reason}
{:ok, 200, %{result: result}} -> result
{:ok, 200, %{"result" => result}} -> result
end
end

Expand All @@ -70,6 +73,7 @@ defmodule Caylir.Graph.Request do

case response do
{:ok, _, %{error: reason}} -> {:error, reason}
{:ok, _, %{"error" => reason}} -> {:error, reason}
{:ok, 200, shape} -> shape
end
end
Expand All @@ -95,6 +99,7 @@ defmodule Caylir.Graph.Request do

case response do
{:ok, _, %{error: reason}} -> {:error, reason}
{:ok, _, %{"error" => reason}} -> {:error, reason}
{:ok, 200, _content} -> :ok
end
end
Expand Down

0 comments on commit f010d2b

Please sign in to comment.