fix(vtex): handle 400 errors in pageTypesFromUrl gracefully#1566
fix(vtex): handle 400 errors in pageTypesFromUrl gracefully#1566
Conversation
When VTEX Catalog API returns a 400 for invalid URL segments (e.g. bot
probes like /%252f/backend/.env), the error was propagating and breaking
section rendering. Return { pageType: "NotFound" } on failure so
getValidTypesFromPageTypes filters it out and the loader returns null
cleanly.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Tagging OptionsShould a new tag be published when this PR is merged?
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds per-segment error handling in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 the current code and only fix it if needed.
Inline comments:
In `@vtex/utils/intelligentSearch.ts`:
- Around line 151-153: Run the code formatter (deno fmt) on the changed block
containing the promise chain that uses STALE and the .then(...).catch(...) chain
so CI passes; specifically format the fragment with the call that ends with "),
STALE).then((res) => res.json()).catch(() => ({ pageType: "NotFound" }))" inside
the intelligent search utility so spacing/line breaks match project style (you
can run `deno fmt` or your editor's formatter to fix indentation and line breaks
for the function handling this promise).
- Around line 149-152: The code maps all exceptions to {pageType: "NotFound"} in
the vcsDeprecated["GET /api/catalog_system/pub/portal/pagetype/:term"] call,
which hides non-400 errors; change the promise handling to only treat HTTP 400
as NotFound and let other failures surface. Concretely, replace the current
.then(res => res.json()).catch(() => ({ pageType: "NotFound" })) chain with
logic that checks res.status: if res.status === 400 return { pageType:
"NotFound" }, else if (!res.ok) throw (or return a rejected promise with) the
response/error so network/5xx/auth errors propagate, and only call res.json()
for successful responses; remove the blanket catch that swallows all errors.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: d8e5664c-150d-4d3d-9c6d-b30f0d33d97e
📒 Files selected for processing (1)
vtex/utils/intelligentSearch.ts
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…8.0) RequestInit is a global Deno/Web API type, no import needed. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
… in 1.188.0)" This reverts commit a778a65.
…rom fetch.ts
@deco/deco removed RequestInit from its exports in 1.188.0.
DecoRequestInit from fetch.ts is the same type (RequestInit & { deco? }).
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Summary
pageTypesFromUrlcalls the VTEX Catalog API (/api/catalog_system/pub/portal/pagetype/:term) for each URL segment to determine page type/%252f/backend/.env), the API returns HTTP 400 with "Invalid parameter 'term'"Promise.all, crashing section rendering and generating noisy error logsFix
Added
.catch(() => ({ pageType: "NotFound" }))to the API call so that:{ pageType: "NotFound" }instead of throwinggetValidTypesFromPageTypesalready filters outNotFound(mapped asnullinPAGE_TYPE_TO_MAP_PARAM)pageTypes, no valid facets, and returnsnullcleanlyTest plan
/%252f/backend/.env— should return null from loader with no error thrown🤖 Generated with Claude Code
Summary by cubic
Gracefully handle HTTP 400s from the VTEX pagetype endpoint in
pageTypesFromUrlby returning a fullPageTypewithpageType: 'NotFound'so bad URL segments (e.g., bot probes) don’t crash sections; non-400 errors still bubble up. Also switchutils/http.tsto useDecoRequestInitfrom ourfetch.tsinstead ofRequestInitfrom@deco/deco(removed in 1.188.0).Written for commit fe1d2ac. Summary will update on new commits.
Summary by CodeRabbit