diff --git a/gracedb/api.py b/gracedb/api.py index 14fadd595ecc83bee0d7af73d9d743f02c51de3b..bd24a887dd182b81720796cf31025eb2c724c880 100644 --- a/gracedb/api.py +++ b/gracedb/api.py @@ -48,7 +48,7 @@ from utils.vfile import VersionedFile # for checking queries in the evnet that the user is external # from view_utils import BadFARRange, check_query_far_range -from query import parseQuery +from query import parseQuery, ParseException ################################################################## @@ -415,7 +415,12 @@ class EventList(APIView): msg = 'FAR query out of range, upper limit must be below %s' % settings.VOEVENT_FAR_FLOOR d = {'error': msg } return Response(d,status=status.HTTP_400_BAD_REQUEST) - + except ParseException: + d = {'error': 'Invalid query' } + return Response(d,status=status.HTTP_400_BAD_REQUEST) + except Exception, e: + d = {'error': str(e) } + return Response(d,status=status.HTTP_500_INTERNAL_SERVER_ERROR) form = SimpleSearchForm(request.GET) if form.is_valid(): events = form.cleaned_data['query'] diff --git a/gracedb/views.py b/gracedb/views.py index 6bc2ed41e9b8f99347573fc688ef717bc2166c8a..fd99104f8bea29166b0847e3e8ac1ec9523aab1c 100644 --- a/gracedb/views.py +++ b/gracedb/views.py @@ -43,7 +43,7 @@ from django.utils.functional import wraps # for checking queries in the evnet that the user is external # from view_utils import BadFARRange, check_query_far_range -from query import parseQuery +from query import parseQuery, ParseException # # A wrapper for retrieving an event and replacing graceid @@ -441,6 +441,12 @@ def search(request, format=""): except BadFARRange: msg = 'FAR query out of range, upper limit must be below %s' % settings.VOEVENT_FAR_FLOOR return HttpResponseBadRequest(msg) + except ParseException: + # If the user's query throws a parse exception, it is safe to + # proceed and show the error message in the search results template (red star) + pass + except Exception, e: + return HttpResponseServerError(str(e)) if form.is_valid(): objects = form.cleaned_data['query'] get_neighbors = form.cleaned_data['get_neighbors']