Current section
4 Versions
Jump to
Current section
4 Versions
Compare versions
4
files changed
+31
additions
-10
deletions
| @@ -20,7 +20,7 @@ Add to dependencies in your `mix.exs` file... | |
| 20 20 | |
| 21 21 | ```elixir |
| 22 22 | def deps do |
| 23 | - [{:graphito, "~> 0.1.0"}] |
| 23 | + [{:graphito, "~> 0.1.1"}] |
| 24 24 | end |
| 25 25 | ``` |
| 26 26 | |
| @@ -62,7 +62,7 @@ iex> Graphito.run(""" | |
| 62 62 | %Graphito.Response{data: %{"jedis" => [%{"name" => "luke"}]}, status: 200, errors: nil, headers: [{"content-type", "application/json"}]} |
| 63 63 | ``` |
| 64 64 | |
| 65 | - If an operation fails the errors are returned: |
| 65 | + If an operation fails the errors are parsed and returned: |
| 66 66 | |
| 67 67 | ```elixir |
| 68 68 | iex> Graphito.run(""" |
| @@ -74,6 +74,16 @@ iex> Graphito.run(""" | |
| 74 74 | """) |
| 75 75 | |
| 76 76 | %Graphito.Response{data: nil, status: 200, errors: [%{"message" => "Cannot query field \"lightzaber\" on type \"Jedi\". Did you mean \"lightsaber\"?"}], headers: [{"content-type", "application/json"}]} |
| 77 | + |
| 78 | + iex> Graphito.run(""" |
| 79 | + query { |
| 80 | + jedis { |
| 81 | + lightsaber |
| 82 | + } |
| 83 | + } |
| 84 | + """) |
| 85 | + |
| 86 | + %Graphito.Response{data: nil, status: 200, errors: [%{"message" => "Third party server timeout", "code" => 503}], headers: [{"content-type", "application/json"}]} |
| 77 87 | ``` |
| 78 88 | |
| 79 89 | If something fails an error is returned: |
| @@ -29,4 +29,4 @@ | |
| 29 29 | {<<"optional">>,false}, |
| 30 30 | {<<"repository">>,<<"hexpm">>}, |
| 31 31 | {<<"requirement">>,<<"0.10.0">>}]]}. |
| 32 | - {<<"version">>,<<"0.1.0">>}. |
| 32 | + {<<"version">>,<<"0.1.1">>}. |
| @@ -35,13 +35,24 @@ defmodule Graphito.Response do | |
| 35 35 | end |
| 36 36 | |
| 37 37 | def handle({:ok, response}) do |
| 38 | - { |
| 39 | - :error, |
| 40 | - %Error{ |
| 41 | - reason: response.status, |
| 42 | - errors: [%{"message" => response.body}] |
| 38 | + with {:ok, response_data} <- Poison.decode(response.body) do |
| 39 | + { |
| 40 | + :error, |
| 41 | + %Error{ |
| 42 | + reason: response.status, |
| 43 | + errors: Map.get(response_data, "errors") |
| 44 | + } |
| 43 45 | } |
| 44 | - } |
| 46 | + else |
| 47 | + _ -> |
| 48 | + { |
| 49 | + :error, |
| 50 | + %Error{ |
| 51 | + reason: response.status, |
| 52 | + errors: [%{"message" => "Unable to parse error response: #{response.body}"}] |
| 53 | + } |
| 54 | + } |
| 55 | + end |
| 45 56 | end |
| 46 57 | |
| 47 58 | @spec handle({:error, %{reason: any()}}) :: {:error, Error.t()} |
| @@ -1,7 +1,7 @@ | |
| 1 1 | defmodule Graphito.MixProject do |
| 2 2 | use Mix.Project |
| 3 3 | |
| 4 | - @version "0.1.0" |
| 4 | + @version "0.1.1" |
| 5 5 | |
| 6 6 | def project do |
| 7 7 | [ |