@@ -2,11 +2,13 @@ import { NextResponse } from "next/server";
22 import { db } from "@/src/lib/db";
33 import { threads } from "@/src/lib/db/schema";
44 import { eq } from "drizzle-orm";
5+import { debug } from "@/src/lib/debug";
56
67 export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
8+ let threadId: number | null = null;
79 try {
810 const { id } = await params;
9- const threadId = parseInt(id);
11+ threadId = parseInt(id);
1012 if (isNaN(threadId)) {
1113 return NextResponse.json({ error: "Invalid thread ID" }, { status: 400 });
1214 }
@@ -55,15 +57,20 @@ export async function PATCH(request: Request, { params }: { params: Promise<{ id
5557 }
5658
5759 return NextResponse.json({ thread: updatedThread[0] });
58- } catch {
60+ } catch (err) {
61+ debug(
62+ `[Threads API] Error updating thread ${threadId ?? "unknown"}:`,
63+ err instanceof Error ? err.message : "Unknown error"
64+ );
5965 return NextResponse.json({ error: "Failed to update thread" }, { status: 500 });
6066 }
6167 }
6268
6369 export async function DELETE(request: Request, { params }: { params: Promise<{ id: string }> }) {
70+ let threadId: number | null = null;
6471 try {
6572 const { id } = await params;
66- const threadId = parseInt(id);
73+ threadId = parseInt(id);
6774 if (isNaN(threadId)) {
6875 return NextResponse.json({ error: "Invalid thread ID" }, { status: 400 });
6976 }
@@ -76,7 +83,11 @@ export async function DELETE(request: Request, { params }: { params: Promise<{ i
7683 }
7784
7885 return NextResponse.json({ success: true });
79- } catch {
86+ } catch (err) {
87+ debug(
88+ `[Threads API] Error deleting thread ${threadId ?? "unknown"}:`,
89+ err instanceof Error ? err.message : "Unknown error"
90+ );
8091 return NextResponse.json({ error: "Failed to delete thread" }, { status: 500 });
8192 }
8293 }