Functions

Instrumentation onRequestError

Export onRequestError from instrumentation.ts to observe framework-captured server errors. Await asynchronous reporting if used; React may transform an error before this hook receives it. This example logs only the route type, never raw request data. It does not intercept every error caught by application code. Source: https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.

Formal Syntax & Structure

nextjs syntaxnextjs
export const onRequestError: Instrumentation.onRequestError = (error, request, context) => { /* report */ }

Working Example

Example Snippetnextjs
import type { Instrumentation } from 'next';export const onRequestError: Instrumentation.onRequestError = (_error,_request,context)=>{ console.error('framework-request-error',context.routeType); };
Next.js Reference