Skip to content

fix: cache middleware now checks response status before storing (fixes #1197) - #11

Open
vaishnavi003-svg wants to merge 1 commit into
SB2318:mainfrom
vaishnavi003-svg:patch-1
Open

fix: cache middleware now checks response status before storing (fixes #1197)#11
vaishnavi003-svg wants to merge 1 commit into
SB2318:mainfrom
vaishnavi003-svg:patch-1

Conversation

@vaishnavi003-svg

Copy link
Copy Markdown

Problem

API cache was saving error responses (401, 403, 500) and serving them as valid data to users.

Fix

Added status code check before caching - now only success responses (200-299) are cached.

Changes

  • middleware/verifyToken.js - Added status validation
  • middleware/cacheMiddleware.js - Only caches 2xx responses
  • app.js - Updated middleware order

Test Results

Response Before After
200 Success ✅ Cached ✅ Cached
401/403 Error ❌ Cached ✅ Not Cached
500 Error ❌ Cached ✅ Not Cached

Code Change

// Before - cached everything
cache.set(key, data);

// After - only cache success
if (res.statusCode >= 200 && res.statusCode < 300) {
    cache.set(key, data);
} else {
    cache.del(key); // clear error cache
}

@github-actions

Copy link
Copy Markdown

Thank you @, for creating the PR and contributing to our UltimateHealth project 💗.
Our team will review the PR and will reach out to you soon! 😇
Make sure that you have marked all the tasks that you are done with ✅.
Thank you for your patience! 😀

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.

1 participant