import log4js from "logger"; const logger = log4js.getLogger("ERROR"); interface ClientErrorReport { message: string; stack?: string; url?: string; line?: number; column?: number; userAgent?: string; tags?: string[]; } export default defineEventHandler(async (event) => { const body = await readBody(event).catch(() => null); if (!body || typeof body.message !== "string") { return R.success({ ok: false }); } const requestId = event.context.requestId ?? "(no-request-id)"; const ip = getRequestIP(event, { xForwardedFor: true }) ?? "unknown"; const tags = Array.isArray(body.tags) ? body.tags.join(",") : "client"; logger.error( `[${requestId}]`, `[CLIENT-ERROR]`, `[${tags}]`, `url=${body.url ?? "-"}`, `ip=${ip}`, `ua=${body.userAgent ?? "-"}`, "\n", body.message, body.stack ?? "", ); return R.success({ ok: true }); });