forked from AkkomaGang/akkoma-fe
WIP some work on making errors less spammy
This commit is contained in:
parent
2e7bd99444
commit
90afcd3420
4 changed files with 43 additions and 32 deletions
|
@ -664,8 +664,7 @@
|
|||
"no_more_statuses": "No more statuses",
|
||||
"no_statuses": "No statuses",
|
||||
"socket_reconnected": "Realtime connection established",
|
||||
"socket_broke": "Realtime connection lost: CloseEvent code {0}",
|
||||
"socket_closed": "No realtime connection, updates can arrive with a delaye until connection is re-established"
|
||||
"socket_broke": "Realtime connection lost: CloseEvent code {0}"
|
||||
},
|
||||
"status": {
|
||||
"favorites": "Favorites",
|
||||
|
|
|
@ -5,6 +5,8 @@ import { Socket } from 'phoenix'
|
|||
|
||||
const api = {
|
||||
state: {
|
||||
connectionBroken: false,
|
||||
retryMultiplier: 1,
|
||||
backendInteractor: backendInteractorService(),
|
||||
fetchers: {},
|
||||
socket: null,
|
||||
|
@ -34,12 +36,18 @@ const api = {
|
|||
},
|
||||
setMastoUserSocketStatus (state, value) {
|
||||
state.mastoUserSocketStatus = value
|
||||
},
|
||||
recoverConnection (state) {
|
||||
state.connectionBroken = false
|
||||
},
|
||||
breakConnection (state) {
|
||||
state.connectionBroken = true
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// Global MastoAPI socket control, in future should disable ALL sockets/(re)start relevant sockets
|
||||
enableMastoSockets (store) {
|
||||
const { state, dispatch } = store
|
||||
const { state, dispatch, commit } = store
|
||||
// Do not initialize unless nonexistent or closed
|
||||
if (
|
||||
state.mastoUserSocket &&
|
||||
|
@ -50,11 +58,13 @@ const api = {
|
|||
) {
|
||||
return
|
||||
}
|
||||
commit('recoverConnection')
|
||||
return dispatch('startMastoUserSocket')
|
||||
},
|
||||
disableMastoSockets (store) {
|
||||
const { state, dispatch } = store
|
||||
const { state, dispatch, commit } = store
|
||||
if (!state.mastoUserSocket) return
|
||||
commit('recoverConnection')
|
||||
return dispatch('stopMastoUserSocket')
|
||||
},
|
||||
|
||||
|
@ -102,6 +112,7 @@ const api = {
|
|||
state.mastoUserSocket.addEventListener('open', () => {
|
||||
// Do not show notification when we just opened up the page
|
||||
if (state.mastoUserSocketStatus !== null) {
|
||||
commit('recoverConnection')
|
||||
dispatch('pushGlobalNotice', {
|
||||
level: 'success',
|
||||
messageKey: 'timeline.socket_reconnected',
|
||||
|
@ -114,15 +125,6 @@ const api = {
|
|||
console.error('Error in MastoAPI websocket:', error)
|
||||
commit('setMastoUserSocketStatus', WSConnectionStatus.ERROR)
|
||||
dispatch('clearOpenedChats')
|
||||
/* Since data in WS event for error is useless it's better to show
|
||||
* generic warning instead of in "close" which actually has some
|
||||
* useful data
|
||||
*/
|
||||
dispatch('pushGlobalNotice', {
|
||||
level: 'error',
|
||||
messageKey: 'timeline.socket_closed',
|
||||
timeout: 5000
|
||||
})
|
||||
})
|
||||
state.mastoUserSocket.addEventListener('close', ({ detail: closeEvent }) => {
|
||||
const ignoreCodes = new Set([
|
||||
|
@ -137,7 +139,11 @@ const api = {
|
|||
dispatch('startFetchingTimeline', { timeline: 'friends' })
|
||||
dispatch('startFetchingNotifications')
|
||||
dispatch('startFetchingChats')
|
||||
setTimeout(() => {
|
||||
console.log('TEST')
|
||||
dispatch('restartMastoUserSocket')
|
||||
}, 1000)
|
||||
if (!state.connectionBroken) {
|
||||
dispatch('pushGlobalNotice', {
|
||||
level: 'error',
|
||||
messageKey: 'timeline.socket_broke',
|
||||
|
@ -145,6 +151,8 @@ const api = {
|
|||
timeout: 5000
|
||||
})
|
||||
}
|
||||
commit('breakConnection')
|
||||
}
|
||||
commit('setMastoUserSocketStatus', WSConnectionStatus.CLOSED)
|
||||
dispatch('clearOpenedChats')
|
||||
})
|
||||
|
|
|
@ -57,12 +57,14 @@ const fetchNotifications = ({ store, args, older }) => {
|
|||
return notifications
|
||||
})
|
||||
.catch((error) => {
|
||||
if (!store.rootState.api.connectionBroken) {
|
||||
store.dispatch('pushGlobalNotice', {
|
||||
level: 'error',
|
||||
messageKey: 'notifications.error',
|
||||
messageArgs: [error.message],
|
||||
timeout: 5000
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -66,12 +66,14 @@ const fetchAndUpdate = ({
|
|||
return { statuses, pagination }
|
||||
})
|
||||
.catch((error) => {
|
||||
if (!store.rootState.api.connectionBroken) {
|
||||
store.dispatch('pushGlobalNotice', {
|
||||
level: 'error',
|
||||
messageKey: 'timeline.error',
|
||||
messageArgs: [error.message],
|
||||
timeout: 5000
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue