diff --git a/combo/apps/search/models.py b/combo/apps/search/models.py
index f35e0867..4859c4a6 100644
--- a/combo/apps/search/models.py
+++ b/combo/apps/search/models.py
@@ -157,7 +157,13 @@ class SearchCell(CellBase):
kwargs['without_user'] = True
# don't send error traces on HTTP errors
kwargs['log_errors'] = 'warn'
- results = requests.get(url, **kwargs).json()
+
+ response = requests.get(url, **kwargs)
+ try:
+ results = response.json()
+ except ValueError:
+ return render_response(service)
+
if service.get('data_key'):
results['data'] = results.get(service['data_key']) or []
hit_templates = {}
diff --git a/tests/test_search.py b/tests/test_search.py
index 2ee67ebd..d1105961 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -113,6 +113,21 @@ def test_search_cell(app):
assert resp.text.count('
') == 1
assert 'barbarbar' in resp.text
+ # search engine does not return valid JSON
+ class FakedResponse(mock.Mock):
+ def json(self):
+ return json.loads(self.content)
+ requests_get.return_value = FakedResponse(content='notjson', status_code=200)
+ resp = app.get('/ajax/search/%s/search_alternate_key/?q=bar' % cell.pk, status=200)
+ assert requests_get.call_args[0][0] == 'http://www.example.net/search/?q=bar'
+ assert '' not in resp.text
+ assert 'no result found' in resp.text
+ requests_get.return_value = FakedResponse(content='500withbadjson', status_code=500)
+ resp = app.get('/ajax/search/%s/search_alternate_key/?q=foo' % cell.pk, status=200)
+ assert requests_get.call_args[0][0] == 'http://www.example.net/search/?q=foo'
+ assert '' not in resp.text
+ assert 'no result found' in resp.text
+
with override_settings(TEMPLATE_VARS=TEMPLATE_VARS):
cell._search_services = {'data': ['search_tmpl']}
cell.save()