Skip to content

Commit 615a3c3

Browse files
Update error handling in fetch_questions and clarify README
Enhanced error messages in `fetch_questions` for clearer exceptions when company data is missing or API fails. Explicitly listed valid `--timeframe` options in README for better user guidance.
1 parent 6539607 commit 615a3c3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.github/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ poetry run python main.py --company google --timeframe 3m
113113

114114
This will fetch the most asked questions at Google in the last 3 months.
115115

116+
The options for `--timeframe` are: `30d`, 3m`, or `6m`.
117+
116118
## Running Tests
117119

118120
Run the tests with the following command:

leetcode/api/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def get_recent_questions_for_company(
179179
:param difficulties: The list of difficulties to filter the questions (default is ['EASY', 'MEDIUM']).
180180
:param top_n: The number of top questions to retrieve (default is 50).
181181
:return: A dictionary containing the list of questions.
182-
:raises Exception: If the API request fails or the response does not contain expected data.
182+
:raises Exception: If the company does not exist, or the API request fails or the response does not contain expected data.
183183
184184
"""
185185
if difficulties is None:
@@ -222,11 +222,16 @@ def get_recent_questions_for_company(
222222
response.raise_for_status() # Raise an exception for HTTP errors
223223

224224
response_data = response.json()
225+
225226
if (
226227
"data" not in response_data
227-
or "favoriteQuestionList" not in response_data["data"]
228-
or "questions" not in response_data["data"]["favoriteQuestionList"]
228+
or response_data["data"].get("favoriteQuestionList") is None
229229
):
230+
raise Exception(
231+
f"No data found for company '{company_slug}' within the timeframe '{timeframe}'. The company might not exist or no questions are available."
232+
)
233+
234+
if "questions" not in response_data["data"]["favoriteQuestionList"]:
230235
raise Exception("Questions not found or invalid response format")
231236

232237
# Limit to top N questions

0 commit comments

Comments
 (0)