Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Fix crash on search parse exceptions (fixes #44)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Jun 13, 2017
1 parent ef3d9b8 commit 192ccde
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Changelog
**Bug fixes**

- Limit the number of results returned by default (fixes #45)
- Fix crash on search parse exceptions (fixes #44)


0.1.0 (2017-05-26)
------------------
Expand Down
8 changes: 6 additions & 2 deletions kinto_elasticsearch/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ def search_view(request, **kwargs):

except elasticsearch.RequestError as e:
# Malformed query.
message = e.info["error"]["reason"]
details = e.info["error"]["root_cause"][0]
if isinstance(e.info["error"], dict):
message = e.info["error"]["reason"]
details = e.info["error"]["root_cause"][0]
else:
message = e.info["error"]
details = None
response = http_error(httpexceptions.HTTPBadRequest(),
errno=ERRORS.INVALID_PARAMETERS,
message=message,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,11 @@ def test_can_aggregate_values(self):
{"key": "abc", "doc_count": 1},
{"key": "efg", "doc_count": 1},
]

def test_search_parse_exception_returns_400(self):
e = elasticsearch.RequestError('', '',
{"error": "Could not find aggregator type"})
with mock.patch("kinto_elasticsearch.indexer.Indexer.search",
side_effect=e):
self.app.post_json("/buckets/bid/collections/cid/search",
headers=self.headers, status=400)

0 comments on commit 192ccde

Please sign in to comment.