Add public cache key, logging, token cache TTL#107
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
api | 9506a0e | Commit Preview URL Branch Preview URL |
May 05 2026, 03:48 AM |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves cache behavior and error handling across the API worker by (1) normalizing public cache keys to avoid cache fragmentation from query strings, (2) adding/adjusting logging and sanitizing user-facing 500 errors, and (3) introducing a TTL-based in-memory cache for the /versions/v1/update bearer token to reduce repeated KV reads.
Changes:
- Add
publicCacheKey/normalizePublicCacheKeyand apply it to Hono cache middleware for publicversionsandstatsroutes. - Add centralized logging for unhandled errors and avoid exposing internal exception messages in API responses (app + central-alerts).
- Add a 60s TTL to the in-memory
UPDATE_TOKENcache and expand tests around token rotation and error sanitization.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/lib/cache.ts |
Adds helpers to normalize public cache keys (drops query/hash) and a Hono keyGenerator. |
src/services/versions/v1/index.ts |
Adds token-cache TTL for update auth and uses publicCacheKey for cached public routes. |
src/services/stats/v1/index.ts |
Uses publicCacheKey for cached stats routes to avoid query-string cache fragmentation. |
src/services/central-alerts/v1/index.ts |
Logs database errors while returning a generic error message to clients. |
src/app/index.ts |
Logs unhandled errors and returns a consistent generic “Internal Server Error” response. |
test/lib/cache.test.ts |
Adds unit coverage for cache-key normalization behavior. |
test/services/versions/v1/index.test.ts |
Adds a token-rotation/TTL test and resets the in-memory token cache between tests. |
test/services/versions/v1/errors.test.ts |
Verifies generic 500 responses don’t expose internal details and resets token cache between tests. |
test/services/versions/v1/middleware.test.ts |
Resets token cache between tests to avoid cross-test contamination. |
test/services/central-alerts/v1/index.test.ts |
Adds coverage ensuring DB exception details are not exposed in responses. |
test/integration/versions/index.test.ts |
Resets token cache between integration tests. |
test/integration/app.test.ts |
Resets token cache between full-app integration tests. |
test/app/index.test.ts |
Resets token cache between app-level tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.