better error handling

This commit is contained in:
Shpuld Shpuldson 2021-02-01 16:16:41 +02:00
parent 1462404e23
commit c0a3ceef00
2 changed files with 12 additions and 3 deletions

View file

@ -563,11 +563,20 @@ const fetchTimeline = ({
}) })
return data return data
}) })
.then((data) => data.json())
.then((data) => { .then((data) => {
if (data.error || data.errors) { if (status >= 500) {
return { errors: ['Server error'] }
}
return data.json()
})
.then((data) => {
if (status >= 400) {
console.log(data.error, data.errors)
data.status = status data.status = status
data.statusText = statusText data.statusText = statusText
if (data.error) {
data.errors = [data.error]
}
return data return data
} }
return { data: data.map(isNotifications ? parseNotification : parseStatus), pagination } return { data: data.map(isNotifications ? parseNotification : parseStatus), pagination }

View file

@ -49,7 +49,7 @@ const fetchAndUpdate = ({
return apiService.fetchTimeline(args) return apiService.fetchTimeline(args)
.then(response => { .then(response => {
if (response.error || response.errors) { if (response.errors) {
throw new Error(`${response.status} ${response.statusText}`) throw new Error(`${response.status} ${response.statusText}`)
} }