Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/api/routes-f/categories/[slug]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ async function requireAdmin(req: NextRequest) {
return { ok: true as const, session };
}

function isUniqueViolation(err: unknown): boolean {
if (!err || typeof err !== "object") {
return false;
}

const code = "code" in err ? (err as { code?: unknown }).code : undefined;
return code === "23505";
}

export async function GET(
_req: NextRequest,
{ params }: { params: Promise<{ slug: string }> }
Expand Down Expand Up @@ -187,6 +196,13 @@ export async function PATCH(

return NextResponse.json(rows[0]);
} catch (err) {
if (isUniqueViolation(err)) {
return NextResponse.json(
{ error: "Category already exists" },
{ status: 409 }
);
}

console.error("[categories/:slug] PATCH error:", err);
return NextResponse.json(
{ error: "Internal server error" },
Expand Down
4 changes: 2 additions & 2 deletions app/api/routes-f/mock/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextRequest, NextResponse } from "next/server";
import { NextResponse } from "next/server";
import { sql } from "@vercel/postgres";

const SCENARIOS = [
Expand Down Expand Up @@ -47,7 +47,7 @@ export async function GET(): Promise<Response> {
return NextResponse.json({ scenarios: SCENARIOS });
}

export async function DELETE(_req: NextRequest): Promise<Response> {
export async function DELETE(): Promise<Response> {
if (isMainnet()) {
return NextResponse.json(
{ error: "Not available in production" },
Expand Down
Loading