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:
AkiraFukushima 2018-07-31 20:16:24 +09:00 committed by GitHub
commit 94071ab3aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 10 deletions

View File

@ -52,30 +52,34 @@ const Favourites = {
}
},
actions: {
fetchFavourites ({ commit }, account) {
async fetchFavourites ({ commit }, account) {
const client = new Mastodon(
account.accessToken,
account.baseURL + '/api/v1'
)
return client.get('/favourites', { limit: 40 })
.then(res => {
const res = await client.get('/favourites', { limit: 40 })
commit('updateFavourites', res.data)
// Parse link header
try {
const link = parse(res.headers.link)
commit('changeMaxId', link.next.max_id)
} catch (err) {
console.error(err)
}
return res.data
})
},
lazyFetchFavourites ({ state, commit, rootState }) {
if (state.lazyLoading) {
return Promise.resolve(null)
}
if (!state.maxId) {
return null
}
commit('changeLazyLoading', true)
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
console.log(state.maxId)
return client.get('/favourites', { max_id: state.maxId, limit: 40 })
.then(res => {
commit('changeLazyLoading', false)