fix: narrow artist PATCH/DELETE 404 catch to Prisma P2025 (rethrow real errors)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { prisma } from "@/lib/db";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
export async function GET(_request: Request, { params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
@@ -41,8 +42,11 @@ export async function PATCH(request: Request, { params }: { params: Promise<{ id
|
||||
try {
|
||||
const updated = await prisma.watchedArtist.update({ where: { id }, data: { autoMonitorFuture } });
|
||||
return Response.json({ id: updated.id, autoMonitorFuture: updated.autoMonitorFuture });
|
||||
} catch {
|
||||
return Response.json({ error: "not found" }, { status: 404 });
|
||||
} catch (e) {
|
||||
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 {
|
||||
await prisma.watchedArtist.delete({ where: { id } });
|
||||
return new Response(null, { status: 204 });
|
||||
} catch {
|
||||
return Response.json({ error: "not found" }, { status: 404 });
|
||||
} catch (e) {
|
||||
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
|
||||
return Response.json({ error: "not found" }, { status: 404 });
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user