add forum
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user