Skip to content

Commit

Permalink
Catch vespa query errors (#186)
Browse files Browse the repository at this point in the history
Initial feedback for api users when running a query with an invalid
query string. The query error has more details so we could send that back
in the future too if we decide it is a good idea to share it
  • Loading branch information
olaughter authored Dec 11, 2023
1 parent fd01125 commit 4185241
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/api/api_v1/routers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from typing import Mapping, Sequence

from cpr_data_access.search_adaptors import VespaSearchAdapter
from fastapi import APIRouter, Depends, Request
from cpr_data_access.exceptions import QueryError
from fastapi import APIRouter, Depends, HTTPException, status, Request
from fastapi.responses import StreamingResponse
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -68,9 +69,14 @@ def _search_request(
if use_vespa:
data_access_search_params = create_vespa_search_params(db, search_body)
# TODO: we may wish to cache responses to improve pagination performance
data_access_search_response = _VESPA_CONNECTION.search(
parameters=data_access_search_params
)
try:
data_access_search_response = _VESPA_CONNECTION.search(
parameters=data_access_search_params
)
except QueryError:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid Query"
)
return process_vespa_search_response(
db,
data_access_search_response,
Expand Down

0 comments on commit 4185241

Please sign in to comment.