Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To report server-side errors that Next.js captures, use the onRequestError hook in instrumentation.ts, normalize a small allowlisted event, and await a POST to an ingestion endpoint or collector you control. An App Router Route Handler can receive that POST, but it is a public endpoint that must validate and limit incoming data. This approach does not automatically capture every process crash, infrastructure failure, browser exception, or error your code catches and suppresses.

What Next.js can capture on the server

The framework integration point is the optional onRequestError(error, request, context) export from the root instrumentation.ts or instrumentation.js file. In a src-based project, place the file alongside app and pages. Next.js calls register() to initialize instrumentation once per server instance, and registration must finish before that instance is ready to handle requests. The current instrumentation guide shows @vercel/otel as an example, but a minimal error reporter does not need OpenTelemetry. The instrumentation API reference documents the hook and its context.

onRequestError runs when Next.js captures a request error. Its context can identify the router (Pages or App) and whether the error occurred during rendering, a route handler, an action, or proxy execution. The request data includes path, method, and headers; treat that breadth as a reason to select fields deliberately, not to forward the entire request.

For Server Component errors, React may process the error before the hook receives it, so the error value may not be the original thrown instance. Next.js documents an error digest as an identifier for this case. Narrow or normalize the error before reading fields, and do not assume that every property of an arbitrary thrown value exists.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Coverage is bounded by the hook

The hook reports errors Next.js captures in request execution. It is not a general process monitor: it does not establish that every unhandled process-level failure, host termination, infrastructure incident, or database error swallowed by application code will be reported. When an application catches an error intentionally and continues, explicitly report it at the catch site if it matters to operations.

The hook became stable in Next.js 15.0.0; the official Next.js 15 announcement says the feature is stable and the experimental.instrumentationHook config option can be removed. Check the documentation for the version actually installed when supporting older projects.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

How to send a compact error event

  1. Add instrumentation. Create instrumentation.ts at the project root, or alongside app and pages under src. Use register() for one-time setup and export onRequestError for request failures.
  2. Normalize the event. Extract only fields needed for diagnosis: an allowlisted category, a normalized message, digest when available, route type or pattern, HTTP method, deployment environment, release identifier if available, and a timestamp or correlation ID generated by the server.
  3. Await reporting. Send the event with an awaited POST to your ingestion URL or collector. The API reference specifically advises awaiting asynchronous reporting work if it needs to complete as part of the hook.
  4. Validate and persist or forward it. On receipt, validate the schema and apply the authentication, anti-abuse, size, and storage controls appropriate to your deployment.

This is an implementation pattern built from the hook and Route Handler APIs, not a complete secure logging service supplied by Next.js. Keep all values derived from requests or thrown errors untrusted. In particular, do not forward the full request object, cookies, authorization headers, arbitrary headers, request body, or user-controlled query strings by default. The hook exposes useful context, but Next.js does not prescribe this exact event schema.

Example App Router receiver

A receiver can live at app/api/errors/route.ts, in a segment that does not also contain a page. Route Handlers use the Web Request/Response APIs; an equivalent Pages Router endpoint uses API Routes. The following is a structural sketch: the validator and storeEvent are application-specific and intentionally not implemented here.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
import { NextResponse } from 'next/server';

export async function POST(request: Request) {
  let body: unknown;

  try {
    body = await request.json();
  } catch {
    return NextResponse.json({ ok: false }, { status: 400 });
  }

  const event = validateErrorEvent(body);
  if (!event) {
    return NextResponse.json({ ok: false }, { status: 400 });
  }

  await storeEvent(event);
  return NextResponse.json({ ok: true }, { status: 202 });
}

Implement a body-size limit as well as schema validation; parsing arbitrary JSON before imposing an appropriate limit can itself consume resources. Choose authentication or another abuse control that fits who is allowed to submit events and how the endpoint is reached. Do not treat an origin check as authentication. Return a minimal success or rejection response, not stack traces or internal backend details. Next.js describes Route Handlers as public HTTP endpoints and advises: “Avoid exposing sensitive information in error messages sent to the client.” See the Backend for Frontend guide.

What the receiving route should protect

Route Handlers support POST and are not cached by default; GET caching is opt-in. POST is therefore the natural method for event ingestion. Keep the endpoint under a distinct API path because a Route Handler and a page cannot occupy the same route segment. These behaviors are documented in the Route Handlers guide.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
  • Validate shape and values: accept only known event categories and bounded strings; reject unexpected fields where practical.
  • Limit volume and size: configure request-body limits, rate limits, and deduplication according to the deployment and expected traffic.
  • Control access: use authentication or other appropriate anti-abuse mechanisms. These protections are not built into Route Handlers by virtue of using Next.js.
  • Keep responses quiet: expose only a simple status to the caller; retain detailed diagnostics in the protected collector or storage system.
  • Choose durable storage: forward to a collector or database suited to the host instead of assuming process memory or local disk will persist.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Runtime and hosting constraints

The instrumentation file can run in Node.js and Edge runtimes. The API reference shows checking process.env.NEXT_RUNTIME to load runtime-specific code; avoid importing Node-only modules on an Edge execution path. Keep the reporting code compatible with the runtime where the relevant request executes.

On serverless hosts, handlers may run as lambdas that do not share state across invocations, may not have writable filesystem access, and may be terminated on timeout. An in-memory queue or local file is therefore not durable storage in that deployment model. Use a storage service or collector designed for the host and keep work on the request path short. Do not assume that awaiting an outbound report guarantees delivery if the runtime itself is terminated.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Do you need sourcemaps, replay, or an observability SDK?

No sourcemap upload or session replay is required to send a compact server error event through this pattern. The event can identify the failure by category, normalized message, digest when present, and route context without recording a user session. The trade-off is diagnostic depth: a small event is easier to constrain and explain, while richer stack or user-session context would require separate decisions about data handling and tooling.

A custom hook and endpoint suit teams that want narrow server request reporting and are prepared to own validation, controls, and storage. A hosted observability SDK can add aggregation and diagnostic workflows, but is optional. Sentry is mentioned in the Next.js 15 announcement in connection with designing onRequestError; that does not make it a prerequisite. Likewise, the instrumentation guide’s @vercel/otel example is useful for broader telemetry but is more than this minimal event path requires. No performance improvement should be inferred without measurement.

Browser errors are a separate reporting path

This design covers server request failures, not browser JavaScript exceptions. Next.js documents instrumentation-client.ts as a separate client-side instrumentation surface that runs after HTML load and before hydration, and recommends keeping it lightweight. Use that surface or explicit browser event listeners if client-side capture is needed; it is not necessary for the backend flow described here. See the instrumentation-client reference.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.