Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
/frameworkPublic archive

feat(nuxt): improve error dx for users - #4539

Merged
pi0 merged 54 commits into
mainfrom
fix/error-dx
Jul 21, 2022
Merged

feat(nuxt): improve error dx for users#4539
pi0 merged 54 commits into
mainfrom
fix/error-dx

Conversation

@danielroe

@danielroedanielroe commented Apr 22, 2022

Copy link
Copy Markdown
Member

🔗 Linked issue

nuxt/nuxt#13788, resolvesnuxt/nuxt#13950

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This PR improves the error experience for users:

  1. fixes an issue where users who manually throw 404s can't escape from the error page (by clearing error after navigating to new route)
  2. renames throwError to showError and allows graceful fallback when nuxt context is not available
  3. allows showError to accept createError params for better dx
  4. allows directly throwing errors created with createError within the Vue lifecycle. (👈 This is now the recommended approach.) This is similar to using createError in server api routes. On server side these will lead to a full page error, but on client can be handled with error boundaries, onErrorCaptured, and so on.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe
danielroe requested a review from pi0April 22, 2022 15:55
@danielroedanielroe self-assigned this Apr 22, 2022
@netlify

netlifyBot commented Apr 22, 2022

Copy link
Copy Markdown

Deploy Preview for nuxt3-docs ready!

NameLink
🔨 Latest commit444a59c
🔍 Latest deploy loghttps://app.netlify.com/sites/nuxt3-docs/deploys/62d9626eb722600008c0c478
😎 Deploy Previewhttps://deploy-preview-4539--nuxt3-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@danielroedanielroe added bug Something isn't working enhancement New feature or request 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage labels Apr 22, 2022
Comment threaddocs/content/2.guide/2.features/7.error-handling.md Outdated
Comment threaddocs/content/2.guide/2.features/7.error-handling.md Outdated
Comment threaddocs/content/3.api/3.utils/throw-error.md Outdated
Comment threadpackages/nuxt/src/app/composables/error.ts Outdated
Comment threadpackages/nuxt/src/app/composables/error.ts Outdated
@pi0pi0 removed the bug Something isn't working label Apr 22, 2022
danielroeand others added 4 commits April 22, 2022 17:20
Co-authored-by: pooya parsa <pyapar@gmail.com>
Co-authored-by: pooya parsa <pyapar@gmail.com>
Co-authored-by: pooya parsa <pyapar@gmail.com>
Co-authored-by: pooya parsa <pyapar@gmail.com>
Comment threaddocs/content/2.guide/2.features/7.error-handling.md Outdated
Comment threaddocs/content/2.guide/2.features/7.error-handling.md Outdated
Comment threaddocs/content/2.guide/2.features/7.error-handling.md Outdated
Comment threadpackages/nuxt/src/app/composables/error.ts Outdated
@danielroe
danielroe requested a review from pi0July 4, 2022 17:07
@pi0

pi0 commented Jul 7, 2022

Copy link
Copy Markdown
Member

Currently, throwError() and throw createError() are behaving the same by showing a full-screen error page. I'm thinking following adjustments before adding:

  • throw createError()
    • Server-side: Full error page
    • Client-side: Let the caller scope gracefully handles (*)
    • Document and recommend since has the benefit of bubbling up from function/composable to their parent for controlled handling
  • throwError()
    • Server and Client: Show full error page
    • Adds a prop to NuxtError (userError: true or fullpageError: true, or ..) to distingoush
    • Possibly deprecate and rename to a more semantic showError function
    • Document the behavior and recommend to only use for critical errors

(*) Graceful client handling: Showing full-error page for Client-Side, is really unnecessary in many cases. For example, when a refresh button fails, we can avoid bailing the whole application into an error state. Using Error boundary is probably best but it is harder to use.

pi0
pi0 approved these changes Jul 21, 2022
@pi0
pi0 merged commit 78618f1 into mainJul 21, 2022
@pi0
pi0 deleted the fix/error-dx branch July 21, 2022 14:29
@Aareksio

Copy link
Copy Markdown

🔥

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3.xenhancementNew feature or request🔨 p3-minor-bugPriority 3: a bug in an edge case that only affects very specific usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allow throwing error within async function

6 participants

@danielroe@Rigo-m@rvmourik@pi0@Aareksio@misaon