Browse Source

Merge branch 'tusooa/nomore-mapundef' into 'develop'

Display better error message for unauthenticated timelines

Closes #1235 and #1044

See merge request pleroma/pleroma-fe!1756
HJ 2 years ago
parent
commit
e7fb5e81c3
1 changed files with 13 additions and 17 deletions
  1. 13 17
      src/services/api/api.service.js

+ 13 - 17
src/services/api/api.service.js

@@ -734,26 +734,22 @@ const fetchTimeline = ({
   const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&')
   const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&')
   url += `?${queryString}`
   url += `?${queryString}`
 
 
-  let status = ''
-  let statusText = ''
-
-  let pagination = {}
   return fetch(url, { headers: authHeaders(credentials) })
   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 }
         return { data: data.map(isNotifications ? parseNotification : parseStatus), pagination }
       } else {
       } else {
-        data.status = status
-        data.statusText = statusText
+        data.errors ||= []
+        data.status = response.status
+        data.statusText = response.statusText
         return data
         return data
       }
       }
     })
     })