Skip to content

"Discover Fact" Button Fails Without Gemini API Key – Needs Graceful Fallback #91

@ragingtitan

Description

@ragingtitan

Description
Currently on the Giveaways page(https://techxninjas-client.vercel.app/giveaways), the "Discover Fact" button does not work as intended. It shows an error saying, "Error:
Gemini API Key is not configured. Please contact administrator."

This appears to be due to the Gemini API key not being set in the deployed environment, which is understandable for security reasons. However, the UI lacks graceful handling of this failure.

To Reproduce
Steps to reproduce the behavior:

  1. Visit https://techxninjas-client.vercel.app/giveaways
  2. Click on the orange button with white text as "Discover Fact".
  3. The error is shown in a red banner saying: "Error: Gemini API Key is not configured. Please contact administrator."

Expected behavior
If the Gemini API key is present and valid:
-> Fetch and display the AI-generated tech fact using Gemini API.

If the Gemini API key is misconfigured or invalid:
-> Fetch some locally available tech facts as fallback.

Screenshots

Image

Suggested Fix
Implement a fallback mechanism using a small local JSON/array of predefined tech facts.

When the Gemini API call fails, catch the error and randomly select a local fallback fact to display.

Optionally, add a console warning for developers if the API key is not present, but suppress the red banner on the UI for end users.

Additional context
This will ensure the user experience remains smooth even if the external AI service is down or unavailable.

Many platforms avoid blocking UI features due to external service configuration by including intelligent fallback logic.

Metadata

Metadata

Assignees

Labels

Level 1This label is used to identify level1 (Easy) issues/prsbugSomething isn't workinggssoc25This label tells that this issue/pr is a part of the official gssoc-25 open source program.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions