debug(gis-search): re-add minimal diagnostic for intermittent failures
Logs session + token + duration on every search. Will revert after cause identified. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,12 @@ export const runtime = "nodejs";
|
|||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
|
const t0 = Date.now();
|
||||||
const session = await getAuthSession();
|
const session = await getAuthSession();
|
||||||
|
const hasTok = !!(session as { accessToken?: string } | null)?.accessToken;
|
||||||
|
const err = (session as { error?: string } | null)?.error;
|
||||||
|
console.log("[gis-search] in session=%s tok=%s err=%s", !!session, hasTok, err ?? "none");
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
}
|
}
|
||||||
@@ -21,16 +26,19 @@ export async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return NextResponse.json(await gisApi.search(q, limit));
|
const data = await gisApi.search(q, limit);
|
||||||
} catch (err) {
|
console.log("[gis-search] ok q=%s dur=%dms", q, Date.now() - t0);
|
||||||
if (err instanceof GisApiError) {
|
return NextResponse.json(data);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof GisApiError) {
|
||||||
|
console.log("[gis-search] gis-api %d %s", e.status, e.code);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: err.code, status: err.status },
|
{ error: e.code, status: e.status },
|
||||||
{ status: err.status },
|
{ status: e.status },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const msg = err instanceof Error ? err.message : String(err);
|
const msg = e instanceof Error ? e.message : String(e);
|
||||||
console.error("[gis-search] internal error:", msg);
|
console.error("[gis-search] internal:", msg);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "internal_error", hint: msg.slice(0, 200) },
|
{ error: "internal_error", hint: msg.slice(0, 200) },
|
||||||
{ status: 500 },
|
{ status: 500 },
|
||||||
|
|||||||
Reference in New Issue
Block a user