-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap external calls with try-except (#67)
* wrap external calls with try-except * remove print_error function
- Loading branch information
1 parent
a6aeeb9
commit 09df6c0
Showing
5 changed files
with
53 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import logging | ||
|
||
# loggers. | ||
logging.basicConfig(level=logging.DEBUG) | ||
logging.basicConfig(level=logging.INFO, | ||
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', | ||
datefmt="%Y-%m-%d %H:%M:%S") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,32 @@ | ||
import logging | ||
from flask import Blueprint, request, jsonify | ||
|
||
from healthtools.search import run_query | ||
|
||
blueprint = Blueprint('search_api', __name__) | ||
log = logging.getLogger(__name__) | ||
|
||
@blueprint.route('/search', methods=['GET'], strict_slashes=False) | ||
@blueprint.route('/search/<doc_type>', methods=['GET'], strict_slashes=False) | ||
def index(doc_type=None): | ||
query = request.args.get('q') | ||
|
||
result, doc_type = run_query(query, doc_type) | ||
try: | ||
result, doc_type = run_query(query, doc_type) | ||
response = jsonify({ | ||
'result': result, | ||
'doc_type': doc_type, | ||
'status': 'OK' | ||
}) | ||
|
||
# Error with run_query (run_query returns false) | ||
if not result: | ||
return jsonify({ | ||
except Exception as err: | ||
response = jsonify({ | ||
'result': {'hits': [], 'total': 0}, | ||
'doc_type': doc_type, | ||
'status': 'FAILED', | ||
'msg': '' # TODO: Pass run_query message here. | ||
}) | ||
log.error('Search failed \n' + str(err)) | ||
|
||
# TODO: Log event here (send to Google Analytics) | ||
|
||
return jsonify({'result': result, 'doc_type': doc_type, 'status': 'OK'}) | ||
return response |