Some error handling

This commit is contained in:
Henry Jameson 2019-12-26 14:12:35 +02:00
parent b619477573
commit 43197c4243
2 changed files with 51 additions and 40 deletions

View file

@ -103,6 +103,10 @@ const settings = {
promise.then(() => {
this.$store.dispatch('setOption', { name: 'useStreamingApi', value })
}).catch((e) => {
console.error('Failed starting MastoAPI Streaming socket', e)
this.$store.dispatch('disableMastoSockets')
this.$store.dispatch('setOption', { name: 'useStreamingApi', value: false })
})
}
}

View file

@ -35,16 +35,18 @@ const api = {
enableMastoSockets (store) {
const { state, dispatch } = store
if (state.mastoUserSocket) return
dispatch('startMastoUserSocket')
return dispatch('startMastoUserSocket')
},
disableMastoSockets (store) {
const { state, dispatch } = store
if (!state.mastoUserSocket) return
dispatch('stopMastoUserSocket')
return dispatch('stopMastoUserSocket')
},
// MastoAPI 'User' sockets
startMastoUserSocket (store) {
return new Promise((resolve, reject) => {
try {
const { state, dispatch } = store
state.mastoUserSocket = state.backendInteractor.startUserSocket({ store })
state.mastoUserSocket.addEventListener(
@ -84,11 +86,16 @@ const api = {
dispatch('restartMastoUserSocket')
}
})
resolve()
} catch (e) {
reject(e)
}
})
},
restartMastoUserSocket ({ dispatch }) {
// This basically starts MastoAPI user socket and stops conventional
// fetchers when connection reestablished
dispatch('startMastoUserSocket').then(() => {
return dispatch('startMastoUserSocket').then(() => {
dispatch('stopFetchingTimeline', { timeline: 'friends' })
dispatch('stopFetchingNotifications')
})