docs: fix types in "Server Utilities" example

This commit is contained in:
OrlS15 2023-09-03 23:35:33 +02:00 committed by GitHub
parent 4e05650cde
commit 31b6265222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}
})
```