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

Expose TS type for onRequestError #67859

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/next/src/server/instrumentation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ export type InstrumentationModule = {
register?(): void
onRequestError?: InstrumentationOnRequestError
}

export namespace Instrumentation {
export type onRequestError = InstrumentationOnRequestError
}
2 changes: 2 additions & 0 deletions packages/next/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export type {
ResolvedViewport,
} from './lib/metadata/types/metadata-interface'

export type { Instrumentation } from './server/instrumentation/types'

/**
* Stub route type for typedRoutes before `next dev` or `next build` is run
* @link https://nextjs.org/docs/app/building-your-application/configuring/typescript#statically-typed-links
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export function onRequestError(err, request, context) {
import { type Instrumentation } from 'next'

export const onRequestError: Instrumentation.onRequestError = (
err,
request,
context
) => {
fetch(`http://localhost:${process.env.PORT}/write-log`, {
method: 'POST',
body: JSON.stringify({
message: err.message,
message: (err as Error).message,
request,
context,
}),
Expand Down
Loading