fix(public): distinguish unavailable data from empty results and missing pages
This commit is contained in:
1 parent
db4acbb46e
commit
445ef13846
16 files changed
+608
-169
No files matched your search
@@ -26,12 +26,15 @@ const CACHE_KEY = "news_list";
|
||||
const FETCH_LIMIT = 30;
|
||||
|
||||
/**
|
||||
* Shared, cached news list used by both the homepage and the news archive so
|
||||
* Shared, cached news preview list used by the homepage and other widgets so
|
||||
* a single "news_list" cache entry serves both routes. Returns at most
|
||||
* `limit` rows with `createdAt` normalized to a Date (the cache round-trip
|
||||
* serializes timestamps to ISO strings).
|
||||
*/
|
||||
export async function getNewsList(limit: number): Promise<NewsListItem[]> {
|
||||
export async function getNewsList(
|
||||
limit: number,
|
||||
options: { throwOnError?: boolean } = {},
|
||||
): Promise<NewsListItem[]> {
|
||||
try {
|
||||
const rows = await cacheNews<NewsListRow[]>(CACHE_KEY, TTL_MS, () =>
|
||||
db
|
||||
@@ -62,6 +65,7 @@ export async function getNewsList(limit: number): Promise<NewsListItem[]> {
|
||||
}))
|
||||
.slice(0, limit);
|
||||
} catch (error) {
|
||||
if (options.throwOnError) throw error;
|
||||
logger.error("Public news query failed", { module: "news", error });
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user