fix: implement hard 404 responses for invalid .json/ URL paths and empty taxonomy pages#940
Conversation
📝 WalkthroughWalkthroughFive Astro workflow route pages replace ChangesWorkflow Pages: Redirect → 404 Hardening
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@site/src/pages/`[locale]/workflows/[slug].astro:
- Around line 71-74: The current error handling in both files is incorrectly
returning a 404 status for all upstream detail-fetch failures, regardless of the
actual failure type. At site/src/pages/[locale]/workflows/[slug].astro lines
71-74, check the is404 flag or variable to distinguish between true not-found
errors and other dependency/upstream failures: if is404 is true, return the 404
response as currently implemented; otherwise, log the actual error and return a
503 or 502 response to properly indicate a server error. Apply the identical
error mapping logic at site/src/pages/workflows/[username].astro lines 60-63 to
ensure consistent handling across both creator routes and prevent false
hard-404s for non-404 upstream failures.
- Around line 143-146: The 404 response fallback does not distinguish between a
genuine missing resource and an upstream fetch failure, which masks service
outages. At site/src/pages/[locale]/workflows/[slug].astro lines 143-146
(anchor), add a check for successful upstream fetch status before returning the
404 response; if the fetch failed, return a 5xx status instead to indicate a
server error. Apply the identical fetch-status gating logic at the sibling
location site/src/pages/workflows/[username].astro lines 110-113 before
returning its hard 404 response. This ensures that ambiguous absence (caused by
fetch failures) is properly distinguished from genuine 404 scenarios.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 81650f30-614f-4838-be2a-24d58e5c5501
📒 Files selected for processing (5)
site/src/pages/[locale]/workflows/[slug].astrosite/src/pages/[locale]/workflows/category/[type].astrosite/src/pages/[locale]/workflows/model/[name].astrosite/src/pages/[locale]/workflows/tag/[tag].astrosite/src/pages/workflows/[username].astro
434dbc3 to
52862d7
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
site/src/pages/[locale]/workflows/category/[type].astro (1)
133-152: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winRemove unreachable “no templates” UI branch.
Since Line 64-69 already returns 404 for
templates.length === 0, the fallback branch here cannot execute. Pruning it will keep behavior clear and reduce maintenance drift.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@site/src/pages/`[locale]/workflows/category/[type].astro around lines 133 - 152, The fallback branch of the ternary operator that displays the "No templates found" message is unreachable because an earlier check at Line 64-69 already returns a 404 response when templates is empty. Remove this dead code by simplifying the conditional to render only the WorkflowGrid component directly without the ternary operator, since the function will have already exited with a 404 if templates.length === 0.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@site/src/pages/`[locale]/workflows/[slug].astro:
- Around line 70-73: 502 error responses are being cached due to inherited
page-level CDN cache policy, allowing temporary upstream failures to be replayed
from cache. Add explicit no-store semantics to prevent caching at all four
affected locations: In site/src/pages/[locale]/workflows/[slug].astro at lines
70-73, add headers: { 'CDN-Cache-Control': 'no-store' } to the detail-fetch 502
Response object. In site/src/pages/[locale]/workflows/[slug].astro at lines
149-152, add the same no-store header to the bogus-slug/index-failure 502
Response object. In site/src/pages/workflows/[username].astro at lines 59-62,
add no-store header to the detail-fetch 502 Response object. In
site/src/pages/workflows/[username].astro at lines 117-120, add no-store header
to the bogus-slug/index-failure 502 Response object.
---
Outside diff comments:
In `@site/src/pages/`[locale]/workflows/category/[type].astro:
- Around line 133-152: The fallback branch of the ternary operator that displays
the "No templates found" message is unreachable because an earlier check at Line
64-69 already returns a 404 response when templates is empty. Remove this dead
code by simplifying the conditional to render only the WorkflowGrid component
directly without the ternary operator, since the function will have already
exited with a 404 if templates.length === 0.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 43826dfe-ee74-419d-b119-1314f3abdf8a
📒 Files selected for processing (5)
site/src/pages/[locale]/workflows/[slug].astrosite/src/pages/[locale]/workflows/category/[type].astrosite/src/pages/[locale]/workflows/model/[name].astrosite/src/pages/[locale]/workflows/tag/[tag].astrosite/src/pages/workflows/[username].astro
52862d7 to
64e9bfa
Compare
…ges and block .json path access
64e9bfa to
b89f1ae
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@site/src/pages/`[locale]/workflows/category/[type].astro:
- Around line 64-69: The early 404 response guard checking if templates.length
=== 0 prevents the empty-state template fallback UI from ever being rendered,
making that code unreachable. Remove the guard that returns a 404 response when
templates is empty so that the "No templates found" message and fallback UI can
be displayed to users when there are no templates available.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: b4694b03-2377-4ed7-99ac-2307025f6351
📒 Files selected for processing (5)
site/src/pages/[locale]/workflows/[slug].astrosite/src/pages/[locale]/workflows/category/[type].astrosite/src/pages/[locale]/workflows/model/[name].astrosite/src/pages/[locale]/workflows/tag/[tag].astrosite/src/pages/workflows/[username].astro
Summary
This PR addresses soft 404 flags by ensuring that the Astro site's server-side rendered (SSR) dynamic pages return a hard 404 HTTP status code (instead of rendering a blank UI shell with
200 OKor triggering a302redirect) when a request is made with invalid data, an empty taxonomy, or an appended trailing slash.Changes Made
Astro.url.pathname.endsWith('.json/')at the top of the dynamic pages' frontmatter to return a hard 404Responseimmediately, blocking bad trailing slash Vercel redirects from matching dynamic layouts.Verification
SKIP_AI_GENERATION=true npm run buildsuccessfully on the local environment.