From c69878cee7a77364afe6ed44a6df109e84273f3b Mon Sep 17 00:00:00 2001 From: tusooa Date: Sat, 14 Jan 2023 22:17:21 -0500 Subject: [PATCH] Display better error message for unauthenticated timelines --- src/services/api/api.service.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 00d1c020d7..af12265e89 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -734,26 +734,22 @@ const fetchTimeline = ({ const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') url += `?${queryString}` - let status = '' - let statusText = '' - - let pagination = {} return fetch(url, { headers: authHeaders(credentials) }) - .then((data) => { - status = data.status - statusText = data.statusText - pagination = parseLinkHeaderPagination(data.headers.get('Link'), { - flakeId: timeline !== 'bookmarks' && timeline !== 'notifications' - }) - return data - }) - .then((data) => data.json()) - .then((data) => { - if (!data.errors) { + .then(async (response) => { + const success = response.ok + + const data = await response.json() + + if (success && !data.errors) { + const pagination = parseLinkHeaderPagination(response.headers.get('Link'), { + flakeId: timeline !== 'bookmarks' && timeline !== 'notifications' + }) + return { data: data.map(isNotifications ? parseNotification : parseStatus), pagination } } else { - data.status = status - data.statusText = statusText + data.errors ||= [] + data.status = response.status + data.statusText = response.statusText return data } })