From 67bd6a4297b446a856c9d501b06ca68e78c754ba Mon Sep 17 00:00:00 2001 From: trafficlunar Date: Sun, 16 Nov 2025 21:27:24 +0000 Subject: [PATCH] fix: send 404 when no miis are found in search API route also remove redundant line in README --- API.md | 10 +++++++--- src/app/api/search/route.ts | 15 +-------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/API.md b/API.md index 9913508..87edda1 100644 --- a/API.md +++ b/API.md @@ -3,8 +3,6 @@ Welcome to the TomodachiShare API Reference! Some routes may require authentication (see [Protected](#protected-endpoints) section - _TODO_). -Schema properties marked with a **\*** are required. - ## Public Endpoints ### **Search Miis** @@ -28,7 +26,7 @@ Searches Miis by name, tags, and description. #### **Examples** ``` -https://tomodachishare.com/api/search?q={query} +https://tomodachishare.com/api/search?q=frieren ``` ``` @@ -43,6 +41,12 @@ Returns an array of Mii IDs: [1, 204, 295, 1024] ``` +When no Miis are found: + +```json +{ "error": "No Miis found!" } +``` + --- ### **Get Mii Image / QR Code / Metadata Image** diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts index 57c7e35..2e219a2 100644 --- a/src/app/api/search/route.ts +++ b/src/app/api/search/route.ts @@ -29,19 +29,6 @@ export async function GET(request: NextRequest) { ...(gender && { gender: { equals: gender } }), }; - const select: Prisma.MiiSelect = { - id: true, - name: true, - imageCount: true, - tags: true, - createdAt: true, - gender: true, - // Like count - _count: { - select: { likedBy: true }, - }, - }; - const skip = (page - 1) * limit; if (sort === "random") { @@ -54,7 +41,7 @@ export async function GET(request: NextRequest) { select: { id: true }, }); - if (matchingIds.length === 0) return; + if (matchingIds.length === 0) return rateLimit.sendResponse({ error: "No Miis found!" }, 404); const rng = seedrandom(randomSeed.toString());