Gracefully handle Elastic errors in user search
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from flask import Blueprint, request
|
from flask import Blueprint, request
|
||||||
|
import elasticsearch.exceptions as elk_ex
|
||||||
from werkzeug import exceptions as wz_exceptions
|
from werkzeug import exceptions as wz_exceptions
|
||||||
from pillar.api.utils import authorization, jsonify
|
from pillar.api.utils import authorization, jsonify
|
||||||
|
|
||||||
@@ -61,7 +62,13 @@ def search_user():
|
|||||||
page_idx = _page_index()
|
page_idx = _page_index()
|
||||||
# result is the raw elasticseach output.
|
# result is the raw elasticseach output.
|
||||||
# we need to filter fields in case of user objects.
|
# we need to filter fields in case of user objects.
|
||||||
|
|
||||||
|
try:
|
||||||
result = queries.do_user_search(searchword, terms, page_idx)
|
result = queries.do_user_search(searchword, terms, page_idx)
|
||||||
|
except elk_ex.ElasticsearchException as ex:
|
||||||
|
resp = jsonify({'_message': str(ex)})
|
||||||
|
resp.status_code = 500
|
||||||
|
return resp
|
||||||
|
|
||||||
# filter sensitive stuff
|
# filter sensitive stuff
|
||||||
# we only need. objectID, full_name, username
|
# we only need. objectID, full_name, username
|
||||||
@@ -97,6 +104,12 @@ def search_user_admin():
|
|||||||
searchword = _valid_search()
|
searchword = _valid_search()
|
||||||
terms = _term_filters()
|
terms = _term_filters()
|
||||||
page_idx = _page_index()
|
page_idx = _page_index()
|
||||||
|
|
||||||
|
try:
|
||||||
result = queries.do_user_search_admin(searchword, terms, page_idx)
|
result = queries.do_user_search_admin(searchword, terms, page_idx)
|
||||||
|
except elk_ex.ElasticsearchException as ex:
|
||||||
|
resp = jsonify({'_message': str(ex)})
|
||||||
|
resp.status_code = 500
|
||||||
|
return resp
|
||||||
|
|
||||||
return jsonify(result)
|
return jsonify(result)
|
||||||
|
Reference in New Issue
Block a user