-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
ISSUE_NUMBER: GH-7
Description
There are multiple try...except blocks for parsing the JSON response from the Gemini API. This could be simplified into a single block.
File: repositories/jobflowapi/controllers/chat.py
Line: 130
Severity: medium
Current Behavior
The code has multiple try...except blocks for parsing the JSON response from the Gemini API.
Expected Behavior
The code should have a single try...except block for parsing the JSON response from the Gemini API.
Suggested Fix
Combine the try...except blocks into a single block.
Code Context
try:
# Find the JSON object in the response
json_start = chat_response.find('{')
json_end = chat_response.rfind('}') + 1
if json_start == -1 or json_end == 0:
raise HTTPException(status_code=500, detail="Invalid response format from chat API")
json_str = chat_response[json_start:json_end]
search_params = json.loads(json_str)
except Exception as e:
print(f"Error parsing JSON from chat API: {e}")
raise HTTPException(status_code=500, detail="Failed to parse search parameters")Additional Notes
This improves the readability and maintainability of the code.
Reactions are currently unavailable