fix: serve GitHub routes when Redis is disabled (500 on every repo page) - #61
Merged
Merged
Conversation
Every cached route returned HTTP 500 with Redis unavailable. RediaClient created and connected a client unconditionally, so the 26 unguarded `await redisClient.get(key)` calls across githubApi, GithubController and InsightController threw into their catch blocks, where a non-HTTP error fell through `error.response?.status || 500`. Fix it in the client rather than at 26 call sites: without REDIS_URL export a no-op that misses the cache, and wrap get/set on the live client so a dropped connection degrades to a miss too. StatsController's bespoke `?.isReady` guards are no longer needed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The core fix is centralized and low-risk, and the remaining feedback is minor (logging clarity and test state isolation).
Pull request overview
This PR fixes GitHub API route failures when Redis is disabled/unavailable by making the Redis client degrade to cache misses instead of throwing, preventing non-HTTP Redis errors from being surfaced as HTTP 500s across repository pages.
Changes:
- Export a disabled/no-op Redis client when
REDIS_URLis not set soawait redisClient.get(...)safely returnsnull. - Wrap
get/seton the live Redis client to tolerate dropped connections by treating failures as cache misses. - Simplify
StatsControllerto always callredisClient.get/set(guards now handled centrally) and add a regression test for the disabled-client behavior.
File summaries
| File | Description |
|---|---|
| server/util/RediaClient.js | Adds disabled-client fallback and guards live client operations to avoid throwing when Redis is unavailable. |
| server/Controllers/StatsController.js | Removes controller-level Redis readiness checks and relies on the centralized client behavior. |
| server/util/RediaClient.test.js | Adds a node:test regression test to validate “Redis disabled” degrades to cache misses. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+10
to
+19
| test('without REDIS_URL the client degrades to a cache miss', async () => { | ||
| delete process.env.REDIS_URL; | ||
| delete require.cache[require.resolve('./RediaClient')]; | ||
| const redisClient = require('./RediaClient'); | ||
|
|
||
| assert.strictEqual(redisClient.isReady, false); | ||
| assert.strictEqual(await redisClient.get('repo:herin7:gitforme'), null); | ||
| await redisClient.set('repo:herin7:gitforme', '{}', { EX: 3600 }); | ||
| redisClient.on('error', () => {}); | ||
| }); |
Comment on lines
+33
to
+37
| try { | ||
| await client.connect(); | ||
| } catch (error) { | ||
| console.error('Redis connection unavailable; continuing with JWT fallback.'); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the
Failed to fetch repository data. Server responded with status 500.error on every repository page.Root cause
GET /api/github/:username/:reponame→fetchRepoDetailsstarts with an unguardedawait redisClient.get(cacheKey).RediaClient.jscreated and connected a Redis client unconditionally, so with Redis disabled that call rejected, landed in the controller'scatch, and hit:A Redis error has no
.response, so every cached route reported 500 — the cache being unavailable was reported as the upstream failing.This affects 26 call sites across
api/githubApi.js,Controllers/GithubController.jsandControllers/InsightController.js— repo details, README, file tree, issues, commits, contributors, hotspots, deployments and dependency health.StatsControllerwas the only file that had been guarded, which is why/api/stats/user-countkept working and masked how broad this was.Fix
Fixed in the client, not at 26 call sites:
REDIS_URL, export a no-op client whosegetreturnsnull. Callers simply miss the cache and fall through to the live GitHub request.get/setso a dropped connection also degrades to a miss instead of throwing. Redis credits expiring mid-flight previously produced the same 500s.StatsController's bespoke?.isReadyguards, now redundant.Behaviour with Redis present is unchanged.
Verification
node --test server/util/RediaClient.test.jspasses — asserts the disabled client reportsisReady: false, returnsnullfromget, and acceptssetwithout throwing.🤖 Generated with Claude Code