Skip to content

Commit

Permalink
add logging for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
abbiesims committed Feb 3, 2025
1 parent b99cc29 commit d781065
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions webapp/docs/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import requests
import concurrent.futures
from sklearn.feature_extraction.text import TfidfVectorizer
import logging

logging.basicConfig(level=logging.INFO)

# ReadTheDocs projects and API endpoints
RTD_PROJECTS = {
Expand Down Expand Up @@ -44,17 +47,37 @@


def fetch_search_results(project, url, query):
"""Fetch search results synchronously from ReadTheDocs API."""
"""
Fetch search results synchronously from ReadTheDocs API
and log responses.
"""
params = {
"q": f"project:{project} {query}",
"page_size": 10, # fetch the first 10 results from each domain
}
try:
response = requests.get(url, params=params, timeout=5)
return (
response.json() if response.status_code == 200 else {"results": []}

logging.info(
f"Fetching search results for {project}: {response.status_code}"
)
except requests.exceptions.RequestException:

if response.status_code == 200:
data = response.json()
logging.info(
f"Request successful for {project}: {response.status_code}"
)
return data
else:
logging.warning(
f"API request failed for {project}: {response.status_code}"
)
logging.warning(f"Response text: {response.text}")

return {"results": []}

except requests.exceptions.RequestException as e:
logging.error(f"Network error fetching {project}: {e}")
return {"results": []}


Expand Down

0 comments on commit d781065

Please sign in to comment.