generative-ai-js icon indicating copy to clipboard operation
generative-ai-js copied to clipboard

fixed the generateContent() produces empty text output

Open akhileshdasari2004 opened this issue 8 months ago • 1 comments

Code Changes Summary: Robust Response Validation:

Added optional chaining (?.) to safely check nested properties in the API response, preventing runtime errors if the response is empty or malformed.

Retry Mechanism:

Introduced a retry mechanism to handle transient issues (e.g., network errors or empty responses). The function retries the API call up to 3 times (configurable) to increase reliability.

Error Handling and Logging:

Added detailed error logging for each failed attempt, including the attempt number, error message, and full response (if available), making debugging easier.

Early Exit on Success:

The function exits early if a valid response is received, avoiding unnecessary retries and improving efficiency.

Code Structure:

Consolidated logic into a single function (getCapitalOfFranceWithRetry) for better readability and maintainability.

akhileshdasari2004 avatar Mar 07 '25 13:03 akhileshdasari2004

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Mar 07 '25 13:03 google-cla[bot]