Skip to content
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

feat: add defineNitroErrorHandler type helper #1923

Merged
merged 10 commits into from
Nov 20, 2023

Conversation

passionate-bram
Copy link
Contributor

πŸ”— Linked issue

#1922

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 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)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

  1. Feat: Creates a defineErrorHandler function that follows the definer pattern.
  2. Feat: Enlist the defineErrorHandler function in the auto-import list.
  3. Docs: Change example of errorHandler on the Configuration page, to use the new function.
  4. Docs: Describes the expected behaviour of an errorHandler in a bit more detail

These changes are needed as described in #1922 I believe the "definer pattern" (I guess it is the factory pattern but the defineX gives it a nice recognizable shape) is an important feature of nitro and provides good ergonomic value to users of the library.

Please note that I made several smaller commits, feel free to pick and choose the changes to make it fit with the project as a whole.

Resolves #1922

πŸ“ Checklist

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

Having a named function presents it in stack traces to developers, clarifying that an error occurred within the default error handler itself.
- The description is extended to explain that the handler can be async
- Update the example to use the `defineErrorHandler` definer function
- Changed the implementation of the error handler to one that uses some of h3's functions.
An alphabetically sorted list is easier to find an entry in and easier to confirm an absence as well.
Copy link
Contributor

nuxt-studio bot commented Nov 17, 2023

βœ… Live Preview ready!

Name Edit Preview Latest Commit
nitro Edit on Studio β†—οΈŽ View Live Preview aaf559c

@passionate-bram passionate-bram changed the title Patch define error handler Introduce defineErrorHandler Nov 17, 2023
@pi0
Copy link
Member

pi0 commented Nov 17, 2023

Thanks! Maybe for consistency with type name we can name if decineNitroErrorHandler?

@passionate-bram
Copy link
Contributor Author

Thanks! Maybe for consistency with type name we can name if decineNitroErrorHandler?

As package maintainer the API (incl naming conventions) would be your decision / responsibility.
I'll leave that for the you to decide, feel free to let me know if you'd like me to make changes to the PR.

@pi0 pi0 changed the title Introduce defineErrorHandler feat: add defineErrorHandler util Nov 20, 2023
@pi0 pi0 changed the title feat: add defineErrorHandler util feat: add defineNitroErrorHandler util Nov 20, 2023
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pi0 pi0 changed the title feat: add defineNitroErrorHandler util feat: add defineNitroErrorHandler type helper Nov 20, 2023
@passionate-bram
Copy link
Contributor Author

I see you added 355ea89 in order to reduce the size of the merge. I can rebase the other commit out as well, then it won't be in the history anymore

@pi0 pi0 merged commit a726e6c into nitrojs:main Nov 20, 2023
4 checks passed
@pi0
Copy link
Member

pi0 commented Nov 20, 2023

I see you added 355ea89 in order to reduce the size of the merge. I can rebase the other commit out as well, then it won't be in the history anymore

Thanks no need we always squash :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide defineErrorHandler when writing a nitro error handler
2 participants