From cffc96571983528979e6590b859b1ade3e417486 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 17 Jul 2024 17:59:30 +0200 Subject: [PATCH] Expose TS type for onRequestError --- packages/next/src/server/instrumentation/types.ts | 4 ++++ packages/next/src/types.ts | 2 ++ .../basic/{instrumentation.js => instrumentation.ts} | 10 ++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) rename test/e2e/on-request-error/basic/{instrumentation.js => instrumentation.ts} (54%) diff --git a/packages/next/src/server/instrumentation/types.ts b/packages/next/src/server/instrumentation/types.ts index 55ee90632932c..1c260cf79fb4e 100644 --- a/packages/next/src/server/instrumentation/types.ts +++ b/packages/next/src/server/instrumentation/types.ts @@ -23,3 +23,7 @@ export type InstrumentationModule = { register?(): void onRequestError?: InstrumentationOnRequestError } + +export namespace Instrumentation { + export type onRequestError = InstrumentationOnRequestError +} diff --git a/packages/next/src/types.ts b/packages/next/src/types.ts index fcb4c47b73cef..396abc74fdb73 100644 --- a/packages/next/src/types.ts +++ b/packages/next/src/types.ts @@ -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 diff --git a/test/e2e/on-request-error/basic/instrumentation.js b/test/e2e/on-request-error/basic/instrumentation.ts similarity index 54% rename from test/e2e/on-request-error/basic/instrumentation.js rename to test/e2e/on-request-error/basic/instrumentation.ts index b9944b351236c..6310bffac27fc 100644 --- a/test/e2e/on-request-error/basic/instrumentation.js +++ b/test/e2e/on-request-error/basic/instrumentation.ts @@ -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, }),