Add a check for rate limiting on timeline fetch
This commit is contained in:
parent
794906f01e
commit
9ea01762a5
1 changed files with 20 additions and 3 deletions
|
@ -462,6 +462,16 @@ const deleteList = ({ id, credentials }) => {
|
|||
})
|
||||
}
|
||||
|
||||
const errorStatusMapper = (response) => {
|
||||
console.log(response)
|
||||
switch (response.status) {
|
||||
case 429:
|
||||
return 'You are rate limited'
|
||||
default:
|
||||
return `Unexpected status: ${response.status}`
|
||||
}
|
||||
}
|
||||
|
||||
const fetchConversation = ({ id, credentials }) => {
|
||||
let urlContext = MASTODON_STATUS_CONTEXT_URL(id)
|
||||
return fetch(urlContext, { headers: authHeaders(credentials) })
|
||||
|
@ -469,7 +479,7 @@ const fetchConversation = ({ id, credentials }) => {
|
|||
if (data.ok) {
|
||||
return data
|
||||
}
|
||||
throw new Error('Error fetching timeline', data)
|
||||
throw new Error(['Error fetching timeline', errorStatusMapper(data)])
|
||||
})
|
||||
.then((data) => data.json())
|
||||
.then(({ ancestors, descendants }) => ({
|
||||
|
@ -485,7 +495,7 @@ const fetchStatus = ({ id, credentials }) => {
|
|||
if (data.ok) {
|
||||
return data
|
||||
}
|
||||
throw new Error('Error fetching timeline', data)
|
||||
throw new Error(['Error fetching timeline', errorStatusMapper(data)])
|
||||
})
|
||||
.then((data) => data.json())
|
||||
.then((data) => parseStatus(data))
|
||||
|
@ -657,8 +667,15 @@ const fetchTimeline = ({
|
|||
})
|
||||
return data
|
||||
})
|
||||
.then((data) => data.json())
|
||||
.then((data) => {
|
||||
if (data.ok) return data.json()
|
||||
|
||||
throw new Error(errorStatusMapper(data))
|
||||
})
|
||||
.then((data) => {
|
||||
if (data.error) {
|
||||
throw new Error(data.error)
|
||||
}
|
||||
if (!data.errors) {
|
||||
return { data: data.map(isNotifications ? parseNotification : parseStatus), pagination }
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue