fix(api): normalize empty list responses
This commit is contained in:
+2
-1
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user