Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle error case for search in Document.API? #29

Open
Anderssorby opened this issue Feb 5, 2020 · 2 comments
Open

Handle error case for search in Document.API? #29

Anderssorby opened this issue Feb 5, 2020 · 2 comments

Comments

@Anderssorby
Copy link

Regarding this line:

{:ok, 200, %{"hits" => %{"hits" => hits}}} = result

Could we handle the error case for the Document.API.search as well? If for example the index doesn't exist it creates a nasty exception.

@Anderssorby
Copy link
Author

Something like:

case result do
          {:error, code, error} ->
            {:error, code, error}
          {:ok, 200, %{"hits" => %{"hits" => hits}}} ->
            Enum.map(hits, fn %{"_source" => source, "_id" => id} ->
              into_struct(id, source)
            end)
end

I can make a PR. Then you can have the option to deal with the errors without breaking existing code.

@radar
Copy link
Owner

radar commented Feb 6, 2020

Yes please do submit a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants