Skip to content

Commit

Permalink
[#39] Fix function clause error
Browse files Browse the repository at this point in the history
Closes #39.
  • Loading branch information
danielberkompas committed Sep 8, 2018
1 parent a1fb889 commit 5621b3f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/elasticsearch/exception.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ defmodule Elasticsearch.Exception do
]
end

defp build(error, query) when is_map(error) do
[
status: nil,
line: nil,
col: nil,
message: error["message"],
type: nil,
query: query,
raw: error
]
end

defp build(error, query) when is_binary(error) do
binary_error(error, query)
end
Expand Down
21 changes: 21 additions & 0 deletions test/elasticsearch/exception_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,26 @@ defmodule Elasticsearch.ExceptionTest do
query: nil
)
end

# See issue: https://github.com/infinitered/elasticsearch-elixir/issues/39
@tag :regression
test "handles arbitrary error maps" do
assert %Exception{type: nil, message: nil, query: nil, raw: %{"message" => nil}} =
Exception.exception(%{
response: %{"message" => nil},
query: nil
})

assert %Exception{
type: nil,
message: "Unable to connect to the server.",
query: nil,
raw: %{"message" => "Unable to connect to the server.", "ok" => false}
} =
Exception.exception(%{
response: %{"message" => "Unable to connect to the server.", "ok" => false},
query: nil
})
end
end
end

0 comments on commit 5621b3f

Please sign in to comment.