diff --git a/src/app/api/people/[id]/route.ts b/src/app/api/people/[id]/route.ts index 769ce316d..2e884c3c4 100644 --- a/src/app/api/people/[id]/route.ts +++ b/src/app/api/people/[id]/route.ts @@ -1,6 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; import { getPersonDetail } from "@/db/queries/people"; -import { isValidUuid } from "@/lib/utils"; import { readIdParam, readJsonBody, z } from "@/lib/api/route-helpers"; import { db } from "@/db"; import { entities } from "@/db/schema"; @@ -67,17 +66,11 @@ export async function GET( _request: Request, { params }: { params: Promise<{ id: string }> }, ) { - const { id } = await params; + const idOrResp = await readIdParam(params); + if (idOrResp instanceof NextResponse) return idOrResp; - if (!isValidUuid(id)) { - return NextResponse.json(null, { status: 400 }); - } - - const person = await getPersonDetail(id); - - if (!person) { - return NextResponse.json(null, { status: 404 }); - } + const person = await getPersonDetail(idOrResp); + if (!person) return NextResponse.json(null, { status: 404 }); return NextResponse.json(person); } diff --git a/src/app/api/projects/[id]/route.ts b/src/app/api/projects/[id]/route.ts index 009999de3..d89cb55fb 100644 --- a/src/app/api/projects/[id]/route.ts +++ b/src/app/api/projects/[id]/route.ts @@ -4,7 +4,6 @@ import { db } from "@/db"; import { entities, entityRelations, interactions, goals } from "@/db/schema"; import { eq, and, desc, inArray } from "drizzle-orm"; import { fetchAttributesByEntityIds } from "@/db/queries/utils"; -import { isValidUuid } from "@/lib/utils"; import { readIdParam, readJsonBody, z } from "@/lib/api/route-helpers"; import { readCronJobs } from "@/lib/crons"; @@ -91,8 +90,9 @@ export async function GET( _req: Request, { params }: { params: Promise<{ id: string }> }, ) { - const { id } = await params; - if (!isValidUuid(id)) return NextResponse.json(null, { status: 400 }); + const idOrResp = await readIdParam(params); + if (idOrResp instanceof NextResponse) return idOrResp; + const id = idOrResp; const [project] = await db .select() diff --git a/src/components/people/PersonDetail.tsx b/src/components/people/PersonDetail.tsx index 28868b876..404429d35 100644 --- a/src/components/people/PersonDetail.tsx +++ b/src/components/people/PersonDetail.tsx @@ -35,7 +35,10 @@ export function PersonDetail({ useEffect(() => { let cancelled = false; fetch(`/api/people/${personId}`) - .then((res) => res.json()) + .then((res) => { + if (!res.ok) throw new Error(`HTTP ${res.status}`); + return res.json(); + }) .then((d: PersonDetailData) => { if (cancelled) return; setData(d); setInteractions(d.interactions); setDescription(d.description); setAttrs(d.attrs); setName(d.name); diff --git a/src/components/projects/ProjectDetail.tsx b/src/components/projects/ProjectDetail.tsx index aced94341..3f5a9457c 100644 --- a/src/components/projects/ProjectDetail.tsx +++ b/src/components/projects/ProjectDetail.tsx @@ -32,7 +32,10 @@ export function ProjectDetail({ // react-hooks/set-state-in-effect cascading-render warning. Promise.resolve().then(() => { if (!cancelled) setRefetching(true); }); fetch(`/api/projects/${projectId}`) - .then((r) => r.json()) + .then((r) => { + if (!r.ok) throw new Error(`HTTP ${r.status}`); + return r.json(); + }) .then((d: ProjectData) => { if (cancelled) return; setData(d);