Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

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

Merged
merged 54 commits into from Jul 21, 2022
Merged

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

merged 54 commits into from Jul 21, 2022

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Apr 22, 2022

πŸ”— Linked issue

nuxt/nuxt#13788, resolves nuxt/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 pi0 April 22, 2022 15:55
@danielroe danielroe self-assigned this Apr 22, 2022
@netlify
Copy link

netlify bot commented Apr 22, 2022

βœ… Deploy Preview for nuxt3-docs ready!

Name Link
πŸ”¨ Latest commit 444a59c
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62d9626eb722600008c0c478
😎 Deploy Preview https://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.

@danielroe danielroe 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
docs/content/2.guide/2.features/7.error-handling.md Outdated Show resolved Hide resolved
docs/content/2.guide/2.features/7.error-handling.md Outdated Show resolved Hide resolved
docs/content/3.api/3.utils/throw-error.md Outdated Show resolved Hide resolved
packages/nuxt/src/app/composables/error.ts Outdated Show resolved Hide resolved
packages/nuxt/src/app/composables/error.ts Outdated Show resolved Hide resolved
@pi0 pi0 removed the bug Something isn't working label Apr 22, 2022
danielroe and 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>
@danielroe danielroe requested a review from pi0 July 4, 2022 17:07
@pi0
Copy link
Member

pi0 commented Jul 7, 2022

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 merged commit 78618f1 into main Jul 21, 2022
@pi0 pi0 deleted the fix/error-dx branch July 21, 2022 14:29
@Aareksio
Copy link

πŸ”₯

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x enhancement New feature or request πŸ”¨ p3-minor-bug Priority 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