From 44c69e6d36fa034d7256d5aac8fcb4146625698b Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Tue, 31 Jul 2018 19:00:13 +0900 Subject: [PATCH] refs #466 Catch raise when the response does not have link header of favourites --- .../TimelineSpace/Contents/Favourites.js | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/renderer/store/TimelineSpace/Contents/Favourites.js b/src/renderer/store/TimelineSpace/Contents/Favourites.js index 5b9ff654..b84b9b6b 100644 --- a/src/renderer/store/TimelineSpace/Contents/Favourites.js +++ b/src/renderer/store/TimelineSpace/Contents/Favourites.js @@ -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 => { - commit('updateFavourites', res.data) - // Parse link header - const link = parse(res.headers.link) - commit('changeMaxId', link.next.max_id) - return res.data - }) + 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)