Fix setting report state, add proper error handling
This commit is contained in:
parent
3e6309ef94
commit
52c22e863e
|
@ -63,6 +63,7 @@
|
||||||
"more": "More",
|
"more": "More",
|
||||||
"loading": "Loading…",
|
"loading": "Loading…",
|
||||||
"generic_error": "An error occured",
|
"generic_error": "An error occured",
|
||||||
|
"generic_error_message": "An error occured: {0}",
|
||||||
"error_retry": "Please try again",
|
"error_retry": "Please try again",
|
||||||
"retry": "Try again",
|
"retry": "Try again",
|
||||||
"optional": "optional",
|
"optional": "optional",
|
||||||
|
|
|
@ -41,7 +41,7 @@ const reports = {
|
||||||
closeUserReportingModal ({ commit }) {
|
closeUserReportingModal ({ commit }) {
|
||||||
commit('closeUserReportingModal')
|
commit('closeUserReportingModal')
|
||||||
},
|
},
|
||||||
setReportState ({ commit, rootState }, { id, state }) {
|
setReportState ({ commit, dispatch, rootState }, { id, state }) {
|
||||||
const oldState = rootState.reports.reports[id].state
|
const oldState = rootState.reports.reports[id].state
|
||||||
console.log(oldState, state)
|
console.log(oldState, state)
|
||||||
commit('setReportState', { id, state })
|
commit('setReportState', { id, state })
|
||||||
|
@ -49,8 +49,13 @@ const reports = {
|
||||||
console.log(report)
|
console.log(report)
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
console.error('Failed to set report state', e)
|
console.error('Failed to set report state', e)
|
||||||
|
dispatch('pushGlobalNotice', {
|
||||||
|
level: 'error',
|
||||||
|
messageKey: 'general.generic_error_message',
|
||||||
|
messageArgs: [e.message],
|
||||||
|
timeout: 5000
|
||||||
|
})
|
||||||
commit('setReportState', { id, state: oldState })
|
commit('setReportState', { id, state: oldState })
|
||||||
console.log(oldState)
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
addReport ({ commit }, report) {
|
addReport ({ commit }, report) {
|
||||||
|
|
|
@ -1270,18 +1270,34 @@ const deleteChatMessage = ({ chatId, messageId, credentials }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const setReportState = ({ id, state, credentials }) => {
|
const setReportState = ({ id, state, credentials }) => {
|
||||||
return promisedRequest({
|
// Can't use promisedRequest because on OK this does not return json
|
||||||
url: PLEROMA_ADMIN_REPORTS,
|
return fetch(PLEROMA_ADMIN_REPORTS, {
|
||||||
|
headers: {
|
||||||
|
...authHeaders(credentials),
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
payload: {
|
body: JSON.stringify({
|
||||||
'reports': [
|
reports: [{
|
||||||
{
|
id,
|
||||||
id,
|
state
|
||||||
state
|
}]
|
||||||
}
|
})
|
||||||
]
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
.then(data => {
|
||||||
|
if (data.status >= 500) {
|
||||||
|
throw Error(data.statusText)
|
||||||
|
} else if (data.status >= 400) {
|
||||||
|
return data.json()
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
if (data.errors) {
|
||||||
|
throw Error(data.errors[0].message)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiService = {
|
const apiService = {
|
||||||
|
|
Loading…
Reference in New Issue