Commit 83f086cc authored by Jun Siang Cheah's avatar Jun Siang Cheah
Browse files

fix: do not return raw search exception due to API keys in URLs

parent 99e4edd3
...@@ -556,7 +556,14 @@ def resolve_hostname(hostname): ...@@ -556,7 +556,14 @@ def resolve_hostname(hostname):
@app.post("/websearch") @app.post("/websearch")
def store_websearch(form_data: SearchForm, user=Depends(get_current_user)): def store_websearch(form_data: SearchForm, user=Depends(get_current_user)):
try: try:
web_results = search_web(form_data.query) try:
web_results = search_web(form_data.query)
except Exception as e:
log.exception(e)
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=ERROR_MESSAGES.WEB_SEARCH_ERROR,
)
urls = [result.link for result in web_results] urls = [result.link for result in web_results]
loader = get_web_loader(urls) loader = get_web_loader(urls)
data = loader.load() data = loader.load()
......
...@@ -75,3 +75,7 @@ class ERROR_MESSAGES(str, Enum): ...@@ -75,3 +75,7 @@ class ERROR_MESSAGES(str, Enum):
INVALID_URL = ( INVALID_URL = (
"Oops! The URL you provided is invalid. Please double-check and try again." "Oops! The URL you provided is invalid. Please double-check and try again."
) )
WEB_SEARCH_ERROR = (
"Oops! Something went wrong while searching the web. Please try again later."
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment