Merge pull request #467 from h3poteto/iss-466
closes #466 Catch raise when the response does not have link header of favourites
This commit is contained in:
commit
94071ab3aa
|
@ -52,30 +52,34 @@ const Favourites = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
fetchFavourites ({ commit }, account) {
|
async fetchFavourites ({ commit }, account) {
|
||||||
const client = new Mastodon(
|
const client = new Mastodon(
|
||||||
account.accessToken,
|
account.accessToken,
|
||||||
account.baseURL + '/api/v1'
|
account.baseURL + '/api/v1'
|
||||||
)
|
)
|
||||||
return client.get('/favourites', { limit: 40 })
|
const res = await client.get('/favourites', { limit: 40 })
|
||||||
.then(res => {
|
commit('updateFavourites', res.data)
|
||||||
commit('updateFavourites', res.data)
|
// Parse link header
|
||||||
// Parse link header
|
try {
|
||||||
const link = parse(res.headers.link)
|
const link = parse(res.headers.link)
|
||||||
commit('changeMaxId', link.next.max_id)
|
commit('changeMaxId', link.next.max_id)
|
||||||
return res.data
|
} catch (err) {
|
||||||
})
|
console.error(err)
|
||||||
|
}
|
||||||
|
return res.data
|
||||||
},
|
},
|
||||||
lazyFetchFavourites ({ state, commit, rootState }) {
|
lazyFetchFavourites ({ state, commit, rootState }) {
|
||||||
if (state.lazyLoading) {
|
if (state.lazyLoading) {
|
||||||
return Promise.resolve(null)
|
return Promise.resolve(null)
|
||||||
}
|
}
|
||||||
|
if (!state.maxId) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
commit('changeLazyLoading', true)
|
commit('changeLazyLoading', true)
|
||||||
const client = new Mastodon(
|
const client = new Mastodon(
|
||||||
rootState.TimelineSpace.account.accessToken,
|
rootState.TimelineSpace.account.accessToken,
|
||||||
rootState.TimelineSpace.account.baseURL + '/api/v1'
|
rootState.TimelineSpace.account.baseURL + '/api/v1'
|
||||||
)
|
)
|
||||||
console.log(state.maxId)
|
|
||||||
return client.get('/favourites', { max_id: state.maxId, limit: 40 })
|
return client.get('/favourites', { max_id: state.maxId, limit: 40 })
|
||||||
.then(res => {
|
.then(res => {
|
||||||
commit('changeLazyLoading', false)
|
commit('changeLazyLoading', false)
|
||||||
|
|
Loading…
Reference in New Issue