2026-08-26 08:45:15 +02:00
|
|
|
import { createLogger } from "@/lib/logger";
|
|
|
|
|
|
2026-08-25 07:51:38 +02:00
|
|
|
export async function register() {
|
|
|
|
|
// Only the Node.js server runtime touches better-sqlite3; the Edge
|
|
|
|
|
// middleware runtime must never import this module.
|
|
|
|
|
if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
|
|
|
const { runMigrations } = await import("@/lib/db/migrate");
|
|
|
|
|
runMigrations();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-26 08:45:15 +02:00
|
|
|
|
|
|
|
|
export async function onRequestError(
|
|
|
|
|
error: unknown,
|
|
|
|
|
request: { path: string; method: string; headers: Record<string, string | string[]> },
|
|
|
|
|
context: { routerKind: string; routePath: string; routeType: string },
|
|
|
|
|
) {
|
|
|
|
|
const log = createLogger("uncaught");
|
|
|
|
|
|
|
|
|
|
// Safety net for errors that escape a route handler's own try/catch (e.g. a
|
|
|
|
|
// bug in code that never reaches withRouteLogging, or a rendering error) -
|
|
|
|
|
// route handlers wrapped in withRouteLogging already log and convert their
|
|
|
|
|
// own errors to a JSON 500, so this rarely double-logs the same failure.
|
|
|
|
|
const digest = typeof error === "object" && error !== null && "digest" in error ? String(error.digest) : undefined;
|
|
|
|
|
log.error("unhandled error", {
|
|
|
|
|
message: error instanceof Error ? error.message : String(error),
|
|
|
|
|
digest,
|
|
|
|
|
stack: error instanceof Error ? error.stack : undefined,
|
|
|
|
|
path: request.path,
|
|
|
|
|
method: request.method,
|
|
|
|
|
routePath: context.routePath,
|
|
|
|
|
routeType: context.routeType,
|
|
|
|
|
});
|
|
|
|
|
}
|