-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix(nuxt): show fatal errors thrown in middleware #31518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
WalkthroughThe changes introduce improvements to error handling during middleware execution in the routing process. A new import, 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/nuxt/src/pages/runtime/plugins/router.ts (1)
215-215
: Consider replacing theany
type for better maintainability.
Using(r: any) => r.default || r
may introduce uncertainty around the imported module type. Providing a more precise type instead ofany
will improve type safety and future refactoring.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/nuxt/src/pages/runtime/plugins/router.ts
(3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/nuxt/src/pages/runtime/plugins/router.ts (2)
packages/nuxt/src/app/composables/router.ts (1)
RouteMiddleware
(45-47)packages/nuxt/src/app/composables/error.ts (3)
createError
(63-78)showError
(19-41)isNuxtError
(58-60)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: codeql (javascript-typescript)
- GitHub Check: code
🔇 Additional comments (3)
packages/nuxt/src/pages/runtime/plugins/router.ts (3)
15-15
: No issues with the new imports.
The additional imports forclearError
,isNuxtError
,showError
anduseError
neatly align with the subsequent usage in this file’s error-handling flow and appear consistent with the PR’s objectives.
224-247
: Logic for middleware result checking looks sound, but verify all return paths.
The checks forfalse
and JavaScriptError
objects effectively prevent navigation or show a 404. In line with Nuxt’s approach, returningtrue
continues the chain, while returning a truthy value (e.g., a route) halts and redirects. Please ensure all return paths are tested to confirm expected behaviour in edge cases (e.g., thrown JavaScript errors vs. custom Nuxt errors).
248-252
: Fatal error handling is properly segregated.
Catching errors and rethrowing them as fatal usingshowError
aligns with the updated error-handling approach. Returning the error for non-fatal scenarios is consistent with the new logic. No further concerns.
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #31518 will not alter performanceComparing Summary
|
🔗 Linked issue
resolves #22731
📚 Description
this handles two additional ways errors can be thrown in middleware - either directly returning a fatal error or throwing an error.
in either case this is checked for the
fatal
property (which triggers showing an error page). Otherwise the error is returned to vue router for handling there.