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 "@/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,9 +42,12 @@ 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) {
|
||||||
|
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
|
||||||
return Response.json({ error: "not found" }, { status: 404 });
|
return Response.json({ error: "not found" }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function DELETE(_request: Request, { params }: { params: Promise<{ id: string }> }) {
|
export async function DELETE(_request: Request, { params }: { params: Promise<{ id: string }> }) {
|
||||||
@@ -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) {
|
||||||
|
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2025") {
|
||||||
return Response.json({ error: "not found" }, { status: 404 });
|
return Response.json({ error: "not found" }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user