fix(api): normalize empty list responses
This commit is contained in:
+3
-3
@@ -4,7 +4,7 @@ import type { Post } from "@/lib/types"
|
||||
import { httpJson } from "./http"
|
||||
|
||||
type Paginated<T> = {
|
||||
items: T[]
|
||||
items: T[] | null
|
||||
meta: {
|
||||
total: number
|
||||
offset: number
|
||||
@@ -40,7 +40,7 @@ export async function listPosts(options?: ListOptions): Promise<Post[]> {
|
||||
const res = await httpJson<Paginated<Post>>(withOffsetLimit("/api/v1/posts", options), {
|
||||
cache: "no-store",
|
||||
})
|
||||
return res.items
|
||||
return res.items ?? []
|
||||
}
|
||||
|
||||
export async function getPostById(postId: string): Promise<Post | undefined> {
|
||||
@@ -80,7 +80,7 @@ export async function listPostsByAuthor(userId: string, options?: ListOptions):
|
||||
cache: "no-store",
|
||||
},
|
||||
)
|
||||
return res.items
|
||||
return res.items ?? []
|
||||
}
|
||||
|
||||
export async function togglePostLike(postId: string, currentlyLiked: boolean): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user