Files
heidi/instrumentation.ts

20 lines
901 B
TypeScript

import type { Instrumentation } from "next";
/**
* Next's hook for an error that reached the server's boundary: thrown while
* rendering a page, or out of a route handler, and not caught by anybody.
*
* It hands the error to the one sink (`lib/domain/errors/sink.ts`) with the
* route's FILE path (`context.routePath`, e.g. `/[locale]/practice`), not
* the address that was requested: the address can carry what a person typed.
* The request's headers are not read at all.
*
* Imported inside the function: this file is also evaluated in runtimes
* that have no database driver, and at build time.
*/
export const onRequestError: Instrumentation.onRequestError = async (error, _request, context) => {
if (process.env.NEXT_RUNTIME !== "nodejs") return;
const { reportServerError } = await import("./lib/domain/errors/report.ts");
await reportServerError(context.routePath, error);
};