Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →For a Next.js App Router application, use the onRequestError hook in a root-level instrumentation.ts file to report server request errors from Route Handlers and Server Actions. Return expected action failures as data, add route-level error boundaries for user recovery, and instrument client-side errors separately. These are complementary layers: a UI boundary does not replace server error reporting.
Which Next.js routes does this cover?
In the App Router, the current term for server endpoints is Route Handlers, rather than the older Pages Router term “API Routes.” Server Actions are also handled as a distinct request context. Next.js instrumentation can identify the router kind, route path, and route type; the route type is route for Route Handlers and action for Server Actions. This setup is for the App Router and should not be assumed to describe a Pages Router application.
As an Amazon Associate I earn from qualifying purchases.
Report server request errors with instrumentation
Create instrumentation.ts at the application root, or under src if that is where the app lives, and export an onRequestError function. Forward the error, request, and context to your observability provider so reports can be associated with the relevant route or action. Follow the current Next.js instrumentation documentation for the function signature and supported runtime details.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsexport async function onRequestError(error, request, context) {
await reportError(error, { request, context })
}
reportError above represents your provider integration; it is not a built-in Next.js function. Adapt the call to the provider’s API and its data-scrubbing requirements. If reporting performs asynchronous work, await it. Next.js specifically cautions: “If you’re running any async tasks in onRequestError, make sure they’re awaited.”
#1 Best Overall
Return expected Server Action failures; throw unexpected errors
Keep ordinary, anticipated outcomes—such as invalid form input or a request that cannot be completed—in the action’s returned value. Render those results as form or action state so a user receives useful feedback without treating routine validation as an incident. Reserve thrown errors for unexpected failures that need operational investigation. See the Next.js error-handling guidance for the framework’s distinction between expected errors and uncaught exceptions.
This distinction improves the signal in production reports: a user correcting an input mistake is a normal application flow, while an unanticipated exception is a failure for the error-reporting path to capture.
Rank #2
Add recovery UI without mistaking it for monitoring
Place an error.tsx file at route-segment boundaries where a local recovery experience makes sense. Consider global-error.tsx when root-level fallback coverage is needed. These boundaries let the interface offer recovery instead of leaving a user at a broken screen, but they do not replace onRequestError or guarantee that every server failure is reported. The error.js reference and production error-handling guide explain the boundary behavior.
Instrument client-side errors separately
Use Next.js’s instrumentation-client.ts entry point for client-side error tracking, following the client instrumentation reference. Do not assume a React error boundary catches every client failure: errors in event handlers and asynchronous callbacks generally need their own reporting path. Verify what your chosen client integration captures and add manual reporting where its documented coverage does not include a failure mode you need.
Rank #3
Keep production error details out of the UI
For production Server Component errors, Next.js shows a generic message and a digest rather than exposing sensitive server exception details in the UI. Keep useful diagnostics in server-side logs and use the digest as a correlation aid when investigating a user report. Show safe recovery guidance to users; do not render stack traces, secret-bearing exception messages, or other internal details. The Next.js error boundary reference describes production error handling.
Review Server Action request limits and origin checks
Next.js documents a default maximum Server Action request body size of 1 MB. The limit is configurable; raise it only when the application has a specific requirement and the resource implications have been considered. Server Actions also use same-origin checks, with additional allowed origins configurable for cases that require them. Review the current serverActions configuration reference before changing either setting.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Production setup checklist
- Server reporting: export
onRequestErrorfrom root-levelinstrumentation.tsand forward the error, request, and context to your reporting system. - Action semantics: return expected validation and request failures; throw unexpected exceptions.
- User recovery: place
error.tsxand, where useful,global-error.tsxat appropriate boundaries. - Client reporting: configure
instrumentation-client.tsand account for event-handler and asynchronous errors that boundaries do not catch. - Safe diagnostics: retain server-side logs, correlate with the production digest, and keep internal details out of user-facing output.
- Request controls: confirm whether the default 1 MB Server Action body limit and same-origin checks fit the application before changing configuration.
The precise provider setup depends on the service and runtime you choose. Confirm its current Next.js support, client and server coverage, source-map and release process, data controls, and any manual instrumentation it requires; the framework hook itself does not establish that a provider automatically captures every failure.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




