fix(api): normalize empty list responses

This commit is contained in:
zetaloop
2026-04-26 01:53:05 +08:00
parent 904148bd55
commit 30c336345e
11 changed files with 28 additions and 23 deletions
+2 -1
View File
@@ -5,7 +5,7 @@ import type { Review } from "@/lib/types"
import { httpJson } from "./http"
type Paginated<T> = {
items: T[]
items: T[] | null
meta: {
total: number
offset: number
@@ -37,6 +37,7 @@ function unwrapItems<T>(value: unknown): T[] {
if ("items" in value) {
const envelope = value as { items?: unknown }
if (Array.isArray(envelope.items)) return envelope.items as T[]
if (envelope.items === null) return []
}
throw new Error("Invalid response")
}