-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
docs: give example of usage of defineWrappedResponseHandler
#33952
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
Added usage example for defineWrappedResponseHandler.
|
|
WalkthroughThe change updates documentation in Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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)
docs/2.directory-structure/1.server.md (1)
131-133: Clearer documentation of response transformation.The usage example effectively demonstrates how to apply
defineWrappedResponseHandler, but it may not be immediately obvious to readers that the returned string'hello world'will be transformed into{ response: 'hello world' }by the wrapper. Consider adding a clarifying comment to help users understand this behaviour.🔎 Suggested enhancement for clarity
~ ~// usage ~export default defineWrappedResponseHandler((event) => 'hello world') + +// usage +// Note: The handler's return value will be wrapped in { response: ... } by defineWrappedResponseHandler +export default defineWrappedResponseHandler((event) => 'hello world')Alternatively, provide a brief note after the code block explaining the transformation:
})+::note
+ThedefineWrappedResponseHandlerutility wraps successful responses in a{ response: ... }object and caught errors in a{ err: ... }object, transforming the original handler's return value.
+::Server Alias
</details> </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used**: Repository UI **Review profile**: CHILL **Plan**: Pro <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 5d9749893c509dc4291b0b134a64784459a0b9cf and 93f2224c8b1a4f07b9103cec05b48c6defff8fc0. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `docs/2.directory-structure/1.server.md` </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
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)
docs/2.directory-structure/1.server.md (1)
131-134: Separate the usage example into its own code block with proper labelling.The added usage example (lines 132–133) is mixed with the utility definition using an inline comment rather than a distinct, properly-labelled code block. This violates the established documentation pattern throughout the file. Additionally, the file path comment uses
.jswhilst the Nuxt documentation convention is to use.tsconsistently.Refactor to separate the definition and usage into distinct code blocks following the pattern used elsewhere in the documentation (e.g., lines 54–56, 76–80).
🔎 Proposed refactoring
Close the first code block after the function definition and open a separate code block for the usage example:
```ts [server/utils/handler.ts] import type { EventHandler, EventHandlerRequest } from 'h3' export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> ( handler: EventHandler<T, D>, ): EventHandler<T, D> => defineEventHandler<T>(async (event) => { try { // do something before the route handler const response = await handler(event) // do something after the route handler return { response } } catch (err) { // Error handling return { err } } }) -~ -~// server/api/hello.get.js -~export default defineWrappedResponseHandler((event) => 'hello world')+
ts [server/api/hello.get.ts] +export default defineWrappedResponseHandler((event) => 'hello world') +</details> </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used**: Repository UI **Review profile**: CHILL **Plan**: Pro <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 93f2224c8b1a4f07b9103cec05b48c6defff8fc0 and 2d00c952f1663a73d3a115070cd408d7f4bc140c. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `docs/2.directory-structure/1.server.md` </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Updated code snippet for hello.get to codeblock
defineWrappedResponseHandler
|
thank you! |
Added usage example for defineWrappedResponseHandler.
🔗 Linked issue
📚 Description