add forum

This commit is contained in:
2025-11-15 10:09:17 +08:00
parent b2f3a8f140
commit d28915ac90
3 changed files with 251 additions and 0 deletions

View File

@@ -349,6 +349,11 @@ export const getCommentsByPostId = async (postId, { page = 1, size = 50 }) => {
comments: response.data.hits.hits.map((hit) => ({ ...hit._source, _id: hit._id })),
};
} catch (error) {
// 如果索引不存在404返回空结果
if (error.response?.status === 404) {
console.warn('评论索引不存在,返回空结果:', INDICES.COMMENTS);
return { total: 0, comments: [] };
}
console.error('获取评论列表失败:', error);
throw error;
}
@@ -407,6 +412,11 @@ export const getEventsByPostId = async (postId) => {
return response.data.hits.hits.map((hit) => ({ ...hit._source, _id: hit._id }));
} catch (error) {
// 如果索引不存在404返回空数组而不是抛出错误
if (error.response?.status === 404) {
console.warn('事件索引不存在,返回空数组:', INDICES.EVENTS);
return [];
}
console.error('获取事件时间轴失败:', error);
throw error;
}