mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +00:00
docs: fix types in "Server Utilities" example
This commit is contained in:
parent
4e05650cde
commit
31b6265222
@ -111,18 +111,20 @@ For example, you can define a custom handler utility that wraps the original han
|
||||
**Example:**
|
||||
|
||||
```ts [server/utils/handler.ts]
|
||||
import type { EventHandler } from 'h3'
|
||||
import type { EventHandler, EventHandlerRequest } from 'h3'
|
||||
|
||||
export const defineWrappedResponseHandler = (handler: EventHandler) =>
|
||||
defineEventHandler(async (event) => {
|
||||
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 }
|
||||
return response
|
||||
} catch (err) {
|
||||
// Error handling
|
||||
return { err }
|
||||
return err
|
||||
}
|
||||
})
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user