From 1f99b0b96038937a69c8f928faa028805a77a854 Mon Sep 17 00:00:00 2001 From: dirtybits Date: Mon, 31 Aug 2026 09:45:28 -0700 Subject: [PATCH] fix(api): default invalid skills page query --- web/__tests__/api/skills-get-cache.test.ts | 8 ++++++++ web/app/api/skills/route.ts | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/web/__tests__/api/skills-get-cache.test.ts b/web/__tests__/api/skills-get-cache.test.ts index e2c2f83d..c72ebc84 100644 --- a/web/__tests__/api/skills-get-cache.test.ts +++ b/web/__tests__/api/skills-get-cache.test.ts @@ -120,6 +120,14 @@ describe("GET /api/skills cache headers", () => { expect(res.headers.get("Cache-Control")).toContain("s-maxage=60"); }); + it("defaults an invalid page query to the first page", async () => { + const res = await GET(makeRequest("?page=not-a-number&mode=fast")); + const body = await res.json(); + + expect(res.status).toBe(200); + expect(body.pagination).toMatchObject({ page: 1, pageSize: 20 }); + }); + it("keeps shared caching when buyer status is not requested", async () => { const res = await GET( makeRequest("?sort=newest&page=1&buyer=11111111111111111111111111111111") diff --git a/web/app/api/skills/route.ts b/web/app/api/skills/route.ts index 4e92b91c..7677d4de 100644 --- a/web/app/api/skills/route.ts +++ b/web/app/api/skills/route.ts @@ -97,6 +97,12 @@ const MAX_PAGE_SIZE = 50; const rpc = createSolanaRpc(DEFAULT_SOLANA_RPC_URL); const configuredSolanaChainContext = getConfiguredSolanaChainContext(); +function parsePage(value: string | null): number { + if (!value) return 1; + const parsed = Number.parseInt(value, 10); + return Number.isFinite(parsed) ? Math.max(1, parsed) : 1; +} + function parsePageSize(value: string | null): number { if (!value) return DEFAULT_PAGE_SIZE; const parsed = Number.parseInt(value, 10); @@ -663,7 +669,7 @@ export async function GET(request: NextRequest) { searchParams.get("buyerStatus") === "1" || searchParams.get("includeBuyerStatus") === "true"; const tags = searchParams.get("tags"); - const page = Math.max(1, parseInt(searchParams.get("page") || "1")); + const page = parsePage(searchParams.get("page")); const pageSize = parsePageSize( searchParams.get("pageSize") ?? searchParams.get("limit") );