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

docs(error-handling): add string vs object errors and update createError jsdoc #762

Merged
merged 5 commits into from
Jun 19, 2024

Conversation

ymansurozer
Copy link
Contributor

πŸ”— Linked issue

#761

❓ 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

I have always been somewhat confused on how to initialize createError, either with a string or an object. Similarly, it was unclear at first which one to use to pass data to the client in an error thrown from the server.

πŸ“ Checklist

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

πŸ—’οΈ Note

This is my first-ever open source contribution so I may not have configured the issue/pr or the contribution itself as needed. I'd love to hear if that is the case and I'll fix whatever is missing.

And just for context: @pi0 this is the pr I am opening per your suggestion over Twitter. Thanks for the nudge!

src/error.ts Outdated
@@ -62,6 +62,7 @@ export class H3Error<DataT = unknown> extends Error {
* Creates a new `Error` that can be used to handle both internal and runtime errors.
*
* @param input {string | (Partial<H3Error> & { status?: number; statusText?: string })} - The error message or an object containing error properties.
* If a string is provided, it will be used as the error `message`. Remember to use either `statusMessage` or `data` to pass error information to the client.
Copy link
Member

Choose a reason for hiding this comment

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

This is nice. We might also add markdown docs and examples (similar, maybe smaller version of docs) here as well so when people hover their mouse on utility in their IDE, they see nice inline docs and tip.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Pooya! I've made some revisions in that direction, what do you think about it now?

ymansurozer and others added 2 commits May 27, 2024 14:13
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
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 merged commit 6499059 into unjs:main Jun 19, 2024
3 checks passed
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.

2 participants