summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Freire <tcfonnet@gmail.com>2016-09-08 10:27:34 -0300
committerTiago Freire <tcfonnet@gmail.com>2016-09-08 10:27:34 -0300
commit53b1199122448a63f980375206bd66aeb716dfe9 (patch)
treee0840e69680dc58e86ea47beea8a335cdf5a47e9
parentAdd Internal Server Error (diff)
Change Errors model and get_keys of Config
-rw-r--r--lib/powerdnsex/config.ex2
-rw-r--r--lib/powerdnsex/managers/zones_manager.ex19
-rw-r--r--lib/powerdnsex/models/error.ex2
3 files changed, 13 insertions, 10 deletions
diff --git a/lib/powerdnsex/config.ex b/lib/powerdnsex/config.ex
index 2cf55f1..0d97cb2 100644
--- a/lib/powerdnsex/config.ex
+++ b/lib/powerdnsex/config.ex
@@ -27,7 +27,7 @@ defmodule PowerDNSex.Config do
###
defp get_key(key) do
- case Application.fetch_env(:powerdns, key) do
+ case Application.fetch_env(:powerdnsex, key) do
{:ok, {:system, env_var_name}} -> System.get_env(env_var_name)
{:ok, value} -> value
_ ->
diff --git a/lib/powerdnsex/managers/zones_manager.ex b/lib/powerdnsex/managers/zones_manager.ex
index fafae13..5fa5a74 100644
--- a/lib/powerdnsex/managers/zones_manager.ex
+++ b/lib/powerdnsex/managers/zones_manager.ex
@@ -43,16 +43,19 @@ defmodule PowerDNSex.Managers.ZonesManager do
defp process_request_response(%Response{body: body, status_code: status}) do
case status do
- s when s == 204 -> :ok
- s when s < 300 ->
- body |> Poison.decode!(as: %Zone{rrsets: [
- %ResourceRecordSet{
- records: [%Record{}]
- }]})
+ s when s == 204 -> {:ok, %{}}
+ s when s < 300 -> {:ok, decode_body(body)}
s when s == 500 ->
- %Error{error: "Internal Server Error"}
+ {:error, %Error{error: "Internal Server Error"}, http_status_code: s}
s when s >= 300 ->
- body |> Poison.decode!(as: %Error{})
+ error = %{Poison.decode!(body,as: %Error{}) | http_status_code: s}
+ {:error, error}
end
end
+
+ defp decode_body(body) do
+ body
+ |> Poison.decode!(as: %Zone{rrsets:
+ [%ResourceRecordSet{records: [%Record{}]}]})
+ end
end
diff --git a/lib/powerdnsex/models/error.ex b/lib/powerdnsex/models/error.ex
index d4b1183..b4397df 100644
--- a/lib/powerdnsex/models/error.ex
+++ b/lib/powerdnsex/models/error.ex
@@ -1,5 +1,5 @@
defmodule PowerDNSex.Models.Error do
- defstruct [:error]
+ defstruct [:error, :http_status_code]
@type t :: %__MODULE__{error: String.t}
end