Skip to content

Conversation

ragingtitan
Copy link

@ragingtitan ragingtitan commented Jul 28, 2025

Bug Fix: "Discover Fact" Button Fails Without Gemini API Key (#91)

Summary

This PR implements a graceful fallback for the "Discover Fact" button on the Giveaways page(https://techxninjas-client.vercel.app/giveaways), addressing the issue where the Gemini API key might be missing or misconfigured in some environments.

Previously, users would see a red error message if the API key wasn’t set, degrading the experience. This fix ensures a seamless fallback to local tech facts from a predefined JSON file if the Gemini API call fails.


Problem

As reported in Issue #91:

Clicking the "Discover Fact" button without a valid Gemini API key results in an error banner that says:
"Gemini API Key is not configured. Please contact administrator."

This affects user experience, especially in environments where the Gemini key is intentionally not exposed (e.g., in demo or preview deployments).


Fix Summary

  • Introduced a fallback mechanism using localTechFacts.json.
  • If process.env.API_KEY is missing:
    • Console logs a developer warning.
    • Fetches a random tech fact from local data (instead of showing a UI error).
  • If Gemini API call fails for any other reason:
    • Logs the error.
    • Displays a fallback fact and shows a gentle UI message ("Unable to fetch from Gemini API, showing a local tech fact instead").
  • Updated button label logic for better UX ("Discover Fact""Discover another Fact" when clicked again).

Before vs After

Before:
2b27b6a6-6bed-4753-b95d-8b5db2428cb5

After:

->When Key is not available or misconfigured.
7aece938-d28a-452d-bed1-a119e5b2e136
Note: Console still logs the warning.

->When gemini call fails.
fadd10d6-1a99-4a7e-9aa4-7f55a18743b7
Note: Console still logs the error for debugging.


Related Code Changes

  • TechFactGenerator.tsx: Main logic for fallback and UI state.
  • localTechFacts.json: Local fallback fact pool. More facts can be added later.

Why This Matters

  • Enhances reliability of the "Discover Fact" feature.
  • Improves end-user experience during API failure or unavailability.
  • Follows robust frontend patterns: fail gracefully, inform developers, delight users.

Copy link

vercel bot commented Jul 28, 2025

@ragingtitan is attempting to deploy a commit to the TechXNinjas' projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Aug 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
techxninjas-client Ready Ready Preview Comment Aug 16, 2025 9:38am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants