From d2bb8327e948f31187fb65cf869ce7740006f079 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Tue, 7 May 2024 14:03:32 +0200 Subject: [PATCH] fix: handle missing topics in forum response --- src/api/forum.js | 4 ++-- test/fixtures/forum/empty.json | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/api/forum.js b/src/api/forum.js index 973a4bf..b72d027 100644 --- a/src/api/forum.js +++ b/src/api/forum.js @@ -9,10 +9,10 @@ export async function getForumReport({ baseUrl }) { throw new Error(`Failed to fetch forum data: ${res.statusText}`); } - const ra = await res.json(); + const parsed = await res.json(); const report = { - topics: ra.topics.map(topic => ({ + topics: (parsed.topics || []).map(topic => ({ id: topic.id, title: topic.title, url: getTopicUrl(baseUrl, topic) diff --git a/test/fixtures/forum/empty.json b/test/fixtures/forum/empty.json index 7b1eb46..9e26dfe 100644 --- a/test/fixtures/forum/empty.json +++ b/test/fixtures/forum/empty.json @@ -1,3 +1 @@ -{ - "topics": [] -} \ No newline at end of file +{} \ No newline at end of file