search: do not try to parse results in case of error (#76022)
gitea/combo/pipeline/head This commit looks good Details

This commit is contained in:
Valentin Deniaud 2023-04-13 17:42:50 +02:00
parent eb91d694db
commit 823c2188b2
2 changed files with 10 additions and 0 deletions

View File

@ -284,6 +284,9 @@ class SearchCell(CellBase):
except ValueError:
return render_response(service)
if results.get('err'):
return render_response(service)
if service.get('data_key'):
results['data'] = results.get(service['data_key']) or []
hit_templates = {}

View File

@ -317,6 +317,13 @@ def test_search_custom_templates(app):
assert '<li><a href="http://example.net/123/">A B</a>' in resp.text
assert '<div>description A</div>' in resp.text
# err != 0 is handled
response = {'err': 1, 'data': 'something'}
mock_json.json.return_value = response
resp = app.get('/ajax/search/%s/search2/?q=foo' % cell.pk, status=200)
assert 'no result found' in resp.text
def test_search_cell_visibility(settings, app):
request = RequestFactory().get('/')