Commit 70361fb2868ed9709c6a140322b22297487214ac
1 parent
fc62c49a
Exists in
master
and in
19 other branches
Better exception when trying to access results for failed multi-search query - fixes #1032
Showing
3 changed files
with
12 additions
and
5 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/results.rb
... | ... | @@ -187,7 +187,11 @@ module Searchkick |
187 | 187 | end |
188 | 188 | |
189 | 189 | def hits |
190 | - @response["hits"]["hits"] | |
190 | + if error | |
191 | + raise Searchkick::Error, "Query error - use the error method to view it" | |
192 | + else | |
193 | + @response["hits"]["hits"] | |
194 | + end | |
191 | 195 | end |
192 | 196 | |
193 | 197 | def misspellings? | ... | ... |
test/multi_search_test.rb
... | ... | @@ -34,9 +34,11 @@ class MultiSearchTest < Minitest::Test |
34 | 34 | assert_equal ["abc", "abd"], products.map(&:name) |
35 | 35 | end |
36 | 36 | |
37 | - # https://github.com/ankane/searchkick/issues/1032 | |
38 | - def test_no_records | |
39 | - products = Product.search("*", order: {created_at: :asc}, execute: false) | |
40 | - assert Searchkick.multi_search([products])[0].results | |
37 | + def test_error | |
38 | + products = Product.search("*", order: {bad_column: :asc}, execute: false) | |
39 | + Searchkick.multi_search([products]) | |
40 | + assert products.error | |
41 | + error = assert_raises(Searchkick::Error) { products.results } | |
42 | + assert_equal error.message, "Query error - use the error method to view it" | |
41 | 43 | end |
42 | 44 | end | ... | ... |