fix: narrow artist PATCH/DELETE 404 catch to Prisma P2025 (rethrow real errors)

This commit is contained in:
Jonathan
2026-07-11 13:58:40 +02:00
parent 1e39c74b16
commit f5ceea8fde
+11 -4
View File
@@ -1,4 +1,5 @@
import { prisma } from "@/lib/db"; import { prisma } from "@/lib/db";
import { Prisma } from "@prisma/client";
export async function GET(_request: Request, { params }: { params: Promise<{ id: string }> }) { export async function GET(_request: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params; const { id } = await params;
@@ -41,8 +42,11 @@ export async function PATCH(request: Request, { params }: { params: Promise<{ id
try { try {
const updated = await prisma.watchedArtist.update({ where: { id }, data: { autoMonitorFuture } }); const updated = await prisma.watchedArtist.update({ where: { id }, data: { autoMonitorFuture } });
return Response.json({ id: updated.id, autoMonitorFuture: updated.autoMonitorFuture }); return Response.json({ id: updated.id, autoMonitorFuture: updated.autoMonitorFuture });
} catch { } catch (e) {
return Response.json({ error: "not found" }, { status: 404 }); if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
return Response.json({ error: "not found" }, { status: 404 });
}
throw e;
} }
} }
@@ -51,7 +55,10 @@ export async function DELETE(_request: Request, { params }: { params: Promise<{
try { try {
await prisma.watchedArtist.delete({ where: { id } }); await prisma.watchedArtist.delete({ where: { id } });
return new Response(null, { status: 204 }); return new Response(null, { status: 204 });
} catch { } catch (e) {
return Response.json({ error: "not found" }, { status: 404 }); if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
return Response.json({ error: "not found" }, { status: 404 });
}
throw e;
} }
} }