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
})
.then((data) => data.json())
.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.statusText = statusText
if (data.error) {
data.errors = [data.error]
}
return data
}
return { data: data.map(isNotifications ? parseNotification : parseStatus), pagination }

View file

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