Merge remote-tracking branch 'origin/hotfix/ct225-drift-recent-errors' into task/BIT-33336-hotfix-drift-npm-ci
This commit is contained in:
commit
40c646ab4b
3 files changed
+119
No files matched your search
@@ -0,0 +1,47 @@
|
|||||||
|
import type { NextRequest } from "next/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export async function POST(request: NextRequest) {
|
||||||
|
const rawBase = process.env.ERROR_REPORTING_ADMIN_API_BASE?.trim();
|
||||||
|
if (!rawBase) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "ERROR_REPORTING_ADMIN_API_BASE is not configured.",
|
||||||
|
},
|
||||||
|
{ status: 503 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const base = rawBase.replace(/\/$/, "");
|
||||||
|
const target = `${base}/api/error-monitoring/resolve-by-pattern`;
|
||||||
|
const body = await request.text();
|
||||||
|
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
Accept: "application/json",
|
||||||
|
"Content-Type": request.headers.get("Content-Type") ?? "application/json",
|
||||||
|
};
|
||||||
|
const cookie = request.headers.get("cookie");
|
||||||
|
if (cookie) {
|
||||||
|
headers.Cookie = cookie;
|
||||||
|
}
|
||||||
|
const resolveHdr = request.headers.get("x-error-resolve-key");
|
||||||
|
if (resolveHdr) {
|
||||||
|
headers["X-Error-Resolve-Key"] = resolveHdr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const upstream = await fetch(target, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: body || undefined,
|
||||||
|
cache: "no-store",
|
||||||
|
});
|
||||||
|
|
||||||
|
const text = await upstream.text();
|
||||||
|
const ct = upstream.headers.get("Content-Type") ?? "application/json; charset=utf-8";
|
||||||
|
return new NextResponse(text, {
|
||||||
|
status: upstream.status,
|
||||||
|
headers: { "Content-Type": ct },
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import type { NextRequest } from "next/server";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export async function POST(request: NextRequest) {
|
||||||
|
const rawBase = process.env.ERROR_REPORTING_ADMIN_API_BASE?.trim();
|
||||||
|
if (!rawBase) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "ERROR_REPORTING_ADMIN_API_BASE is not configured.",
|
||||||
|
},
|
||||||
|
{ status: 503 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const base = rawBase.replace(/\/$/, "");
|
||||||
|
const target = `${base}/api/error-monitoring/resolve-fixed-patterns`;
|
||||||
|
const body = await request.text();
|
||||||
|
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
Accept: "application/json",
|
||||||
|
"Content-Type": request.headers.get("Content-Type") ?? "application/json",
|
||||||
|
};
|
||||||
|
const cookie = request.headers.get("cookie");
|
||||||
|
if (cookie) {
|
||||||
|
headers.Cookie = cookie;
|
||||||
|
}
|
||||||
|
const resolveHdr = request.headers.get("x-error-resolve-key");
|
||||||
|
if (resolveHdr) {
|
||||||
|
headers["X-Error-Resolve-Key"] = resolveHdr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const upstream = await fetch(target, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: body || undefined,
|
||||||
|
cache: "no-store",
|
||||||
|
});
|
||||||
|
|
||||||
|
const text = await upstream.text();
|
||||||
|
const ct = upstream.headers.get("Content-Type") ?? "application/json; charset=utf-8";
|
||||||
|
return new NextResponse(text, {
|
||||||
|
status: upstream.status,
|
||||||
|
headers: { "Content-Type": ct },
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -109,6 +109,29 @@ function parseStatusList(raw: string | undefined): string[] | null {
|
|||||||
return parts.length > 0 ? parts : ['open', 'investigating'];
|
return parts.length > 0 ? parts : ['open', 'investigating'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function slimContext(ctx: Record<string, unknown> | null): Record<string, unknown> | null {
|
||||||
|
if (!ctx) return null;
|
||||||
|
const out: Record<string, unknown> = {};
|
||||||
|
for (const key of Object.keys(ctx).slice(0, 40)) out[key] = slimContextValue(ctx[key], 0);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function slimContextValue(value: unknown, depth: number): unknown {
|
||||||
|
if (depth > 3) return '[nested]';
|
||||||
|
if (typeof value === 'string') return value.length > 1500 ? `${value.slice(0, 1500)}…` : value;
|
||||||
|
if (value == null || typeof value === 'number' || typeof value === 'boolean') return value;
|
||||||
|
if (Array.isArray(value)) return value.slice(0, 20).map((item) => slimContextValue(item, depth + 1));
|
||||||
|
if (typeof value === 'object') {
|
||||||
|
const nested: Record<string, unknown> = {};
|
||||||
|
for (const [key, item] of Object.entries(value as Record<string, unknown>).slice(0, 30)) {
|
||||||
|
nested[key] = slimContextValue(item, depth + 1);
|
||||||
|
}
|
||||||
|
return nested;
|
||||||
|
}
|
||||||
|
return String(value).slice(0, 500);
|
||||||
|
}
|
||||||
|
|
||||||
async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply): Promise<void> {
|
async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply): Promise<void> {
|
||||||
const db = request.server.db;
|
const db = request.server.db;
|
||||||
|
|
||||||
@@ -321,6 +344,8 @@ async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply):
|
|||||||
if (paperclip_project_id !== '') {
|
if (paperclip_project_id !== '') {
|
||||||
rowOut.paperclip_project_id = paperclip_project_id;
|
rowOut.paperclip_project_id = paperclip_project_id;
|
||||||
}
|
}
|
||||||
|
const contextData = slimContext(ctx);
|
||||||
|
if (contextData) rowOut.context_data = contextData;
|
||||||
return rowOut;
|
return rowOut;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user